Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by: Hanan Hardan

Similar presentations


Presentation on theme: "Prepared by: Hanan Hardan"— Presentation transcript:

1 Prepared by: Hanan Hardan
Image Processing Chapter(3) Part 3:Intensity Transformation and spatial filters Prepared by: Hanan Hardan

2 Gray-level Slicing This technique is used to highlight a specific range of gray levels in a given image. – Similar to thresholding – Other levels can be suppressed or maintained – Useful for highlighting features in an image It can be implemented in several ways, but the two basic themes are: One approach is to display a high value for all gray levels in the range of interest and a low value for all other gray levels. The second approach, based on the transformation brightens the desired range of gray levels but preserves gray levels unchanged.

3 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions. 2. Intensity-Level Slicing (gray level slicing) Highlighting a specific range of intensities in an image. Approach Approach 2 display in one value(e.g white) all the values in the range of interest , and in another (e.g black) all other intensities Brightens or darkens the desired range of intensities but leaves all other intensity levels in the image unchanged

4 Gray-level Slicing

5 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions. 2. Intensity-Level Slicing (gray level slicing) – example: approach 1 example: apply intensity level slicing in Matlab to read cameraman image , then If the pixel intensity in the old image is between (100  200) convert it in the new image into 255 (white). Otherwise convert it to 0 (black).

6 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions. 2. Intensity-Level Slicing (gray level slicing) example: approach 1 example: apply intensity level slicing in Matlab to read cameraman image , then If the pixel intensity in the old image is between (100  200) convert it in the new image into 255 (white). Otherwise convert it to 0 (black). Solution: x=imread('cameraman.tif'); y=x; [w h]=size(x); for i=1:w for j=1:h if x(i,j)>=100 && x(i,j)<=200 y(i,j)=255; else y(i,j)=0; end figure, imshow(x); figure, imshow(y);

7 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions. 2. Intensity-Level Slicing (gray level slicing) example: approach 2 example: apply intensity level slicing in Matlab to read cameraman image , then If the pixel intensity in the old image is between (100  200) convert it in the new image into 255 (white). Otherwise it leaves it the same.

8 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions. 2. Intensity-Level Slicing (gray level slicing) example: approach 2 example: apply intensity level slicing in Matlab to read cameraman image , then If the pixel intensity in the old image is between (100  200) convert it in the new image into 255 (white). Otherwise it leaves it the same. Solution: x=imread('cameraman.tif'); y=x; [w h]=size(x); for i=1:w for j=1:h if x(i,j)>=100 && x(i,j)<=200 y(i,j)=255; else y(i,j)=x(i,j); end figure, imshow(x); figure, imshow(y);

9 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions. 2. Intensity-Level Slicing (gray level slicing) Homework example: apply intensity level slicing (approch2) in Matlab to read moon image , then If the pixel intensity in the old image is between (0  20) convert it in the new image into 130.

10 Bit-plane Slicing Pixels are digital numbers, each one composed of bits. Instead of highlighting gray-level range, we could highlight the contribution made by each bit. This method is useful and used in image compression. Most significant bits contain the majority of visually significant data.

11 Ch3, lesson3: piecewise Linear transformation functions.
piecewise Linear transformation functions Bit-Plane Slicing Remember that pixels are digital numbers composed of bits. 8-bit Image composed of 8 1-bit planes

12 Bit-Plane Slicing Often by isolating particular bits of the pixel values in an image we can highlight interesting aspects of that image – Higher-order bits usually contain most of the significant visual information – Lower-order bits contain subtle details

13 Bit-Plane Slicing

14 Ch3, lesson3: piecewise Linear transformation functions.
3. Bit-Plane Slicing 14

15 Bit-Plane Slicing

16 3. Bit-Plane Slicing (example)
Ch3, lesson3: piecewise Linear transformation functions. 3. Bit-Plane Slicing (example) 100 We have to use bit get and bit set to extract 8 images; Image of bit1: Image of bit2: Image of bit3: Image of bit4: 4 Image of bit6: Image of bit8: Image of bit5: Image of bit7: 32 64 16

17 3. Bit-Plane Slicing- programmed
Ch3, lesson3: piecewise Linear transformation functions. 3. Bit-Plane Slicing- programmed example: apply bit-plane slicing in Matlab to read cameraman image , then extract the image of bit 6. Solution: x=imread('cameraman.tif'); y=x*0; [w h]=size(x); for i=1:w for j=1:h b=bitget(x(i,j),6); y(i,j)=bitset(y(i,j),6,b); end figure, imshow(x); figure, imshow(y);

18 Histogram Processing What is a Histogram?
In Statistics, Histogram is a graphical representation showing a visual impression of the distribution of data. An Image Histogram is a type of histogram that acts as a graphical representation of the lightness/color distribution in a digital image. It plots the number of pixels for each value.

19 Preview.. histogram Histogram? The histogram of a digital image with gray levels in the range [0, L-1] is a discrete function: h(rk) = nk Where: rk : kth gray level nk : # of pixels with having gray level rk

20 Histogram Processing It is common practice to normalize a histogram by dividing each of its values by the total number of pixels in the image, denoted by n. Thus, a normalized histogram is given by p(rk) = nk / n, for k = 0, 1, …, L -1. Thus, p(rk) gives an estimate of the probability of occurrence of gray level rk. Note that the sum of all components of a normalized histogram is equal to 1.

21 Why Histogram? Histograms are the basis for numerous spatial domain processing techniques Histogram manipulation can be used effectively for image enhancement Histograms can be used to provide useful image statistics Information derived from histograms are quite useful in other image processing applications, such as image compression and segmentation.

22 Histogram of the image:
Ch3, lesson 4: histogram Histogram of the image: histogram هو تمثيل لعدد البكسل في كل قيمة لونية من درجات gray levels h(rk) = nk Where: rk : kth gray level nk : # of pixels with having gray level rk

23 Histogram of the image:
Ch3, lesson 4: histogram Histogram of the image: For example: we have 600 pixels having the intensity value ≈ 160

24 Introductory Example of Histograms
As an introduction to the role of histogram processing in image enhancement, consider Fig shown in four basic gray-level characteristics: dark, light, low contrast, and high contrast. The right side of the figure shows the histograms corresponding to these images. The horizontal axis of each histogram plot corresponds to gray level values, rk. The vertical axis corresponds to values of h(rk)=nk or p(rk)=nk/n if the values are normalized. Thus, as indicated previously, these histogram plots are simply plots of h(rk)=nk versus rk or p(rk)=nk/n versus rk.

25 Histogram of the image:
Ch3, lesson 4: histogram Histogram of the image: 25

26 Introductory Example of Histograms… Cont.
We note in the dark Image that the components of the histogram are concentrated on the low (dark) side of the gray scale. Similarly, the components of the histogram of the bright image are biased toward the high side of the gray scale. An image with low contrast has a histogram that will be narrow and will be centered toward the middle of the gray scale. For a monochrome image this implies a dull, washed-out gray look. Finally, we see that the components of the histogram in the high-contrast image cover a broad range of the gray scale and, further, that the distribution of pixels is not too far from uniform, with very few vertical lines being much higher than the others. Intuitively, it is reasonable to conclude that an image whose pixels tend to occupy the entire range of possible gray levels and, in addition, tend to be distributed uniformly, will have an appearance of high contrast and will exhibit a large variety of gray tones.

27 Histogram in MATLAB h = imhist (f, b) Where f, is the input image, h is the histogram, b is number of bins (tick marks) used in forming the histogram (b = 255 is the default) A bin, is simply, a subdivision of the intensity scale. For example, if we are working with uint8 images and we let b = 2, then the intensity scale is subdivided into two ranges: 0 – 127 and 128 – 255. the resulting histograms will have two values: h(1) equals to the number of pixels in the image with values in the interval [0,127], and h(2) equal to the number of pixels with values in the interval [ ].

28 Histogram in MATLAB We obtain the normalized histogram simply by using the expression. p = imhist (f, b) / numel(f) numel (f): a MATLAB function that gives the number of elements in array f (i.e. the number of pixels in an image.

29 Other ways to display Histograms
Consider an image f. The simplest way to plot its histogram is to use imhist with no output specified: >> imhist (f); Figure 3.7(a) shows the result.

30 Other ways to display Histograms
The histogram displayed in figure 3.7(a), is the default histogram in MATLAB However, there are other ways to plot a histogram. Histograms often are plotted using bar graphs. For this purpose we can use function bar (horz, v, width) (1) where v is a row vector containing the points to be plotted, horz is a vector of the same dimension as v that contains the increments of the horizontal scale, and width is a number between 0 and 1. if horz is omitted, the horizontal axis is divided in units from 0 to length(v). When width is 1 the bars touch; when it is 0 the bars are simply vertical lines. The default value is 0.8.

31 Other ways to display Histograms
The following statements produce a bar graph, with the horizontal axis divided into groups of 10 levels: >> h = imhist(f); >>h1 = h(1:10:256); >> horz = 1:10:256; >> bar (horz, h1); >> axis ([ ]) >> set (gca, ‘xtick’, 0:50:255) >>set (gca, ‘ytick’, 0:2000:15000) Figure 3.7(b) shows the result. The axis function has the syntax: axis ([horizmin horzmax vertmin vertmax]) Which sets the minimum and maximum values in the horizontal and vertical axes.

32 Other ways to display Histograms
gca: get current axes (the axes of the figure last displayed) xtick and ytick set the horizontal and vertical ticks in the interval shown. Axes labels can be added to the horizontal and vertical axes of a graph using the functions xlabel (‘text string’, ‘fontsize’, size); ylabel (‘text string’, ‘fontsize’, size); Where size is the font size in points Text can be added to the body of the figure using function: text (xloc, yloc, ‘text string’, ‘font size’, size); where: xloc and yloc define the location where text starts.

33 Other ways to display Histograms
Note: functions that set axis values and labels are used after the function has been plotted. A title can be added to a plot using: title(‘text string’)

34 Other ways to display Histograms
A stem graph can be used to display the histogram: stem (horz, v, ‘fill’, ‘LineStyle’); (2) where v and horz as in bar function. where ‘LineStyle’ represents the shape of lines in the graph if ‘fill’ is used, and the marker is circle, square or diamond, the marker is filled, with the color specified. The default color is black. To set the shape and the color of the marker, use the following Set statements (example): >> stem (horz, v, ‘fill’, ‘- -’); >> stem (h, ‘MarkerFaceColor’, ‘r’, ‘marker’, ‘s’); This sentence will change the shape of the marker to red square.

35 Other ways to display Histograms

36 Other ways to display Histograms
Plot graph, can be used to display the histogram with straight lines, the syntax is: h = imhist(f); plot (h, ‘color-linestyle-marker’) (3) >> plot (h, 'color','r','linestyle','--','Marker','s') the arguments are specified preciously.

37 Histogram equalization of the image:
Ch3, lesson 5: histogram equalization Histogram equalization of the image: We have this image in matlab called pout.tif, when we plot its histogram it is showed like this: Notice that the pixels intensity values are concentrated on the middle (low contrast) 37

38 Histogram equalization of the image:
Ch3, lesson 5: histogram equalization Histogram equalization of the image: histogram equalization : is the process of adjusting intensity values of pixels. The process which increases the dynamic range of the gray level in a law contrast image to cover full range of gray levels. Im matlab : we use histeq function Histogram produces pixels having values that are distributed throughout the range 38

39 Histogram equalization of the image:
Ch3, lesson 5: histogram equalization Histogram equalization of the image: Notice that histogram equalization does not always produce a good result 39

40 Equalization (mathematically)
Ch3, lesson 5: histogram equalization Equalization (mathematically) g(x) = (L/n). T(X) -1 Where, G(X) : the new image after equalization L: No of gray levels 2n n: No of pixels T(x): cumulative sum of each gray level

41 Equalization (mathematically)
Ch3, lesson 5: histogram equalization Equalization (mathematically) G(x) T(X)مجموع تراكمي للبكسل X عدد البكسل لكل Graylevel L graylevels 1 4 3 9 5 2 15 6 21 27 29 7 32 Assume that we have (3bits per pixels) or 8 levels of grayscale, and we want to equalize the following image example. G(x)=(L/n). T(X) -1 =(8/32). T(x) -1 8 عدد ال graylevel No of pixels عدد البكسلات الكلي


Download ppt "Prepared by: Hanan Hardan"

Similar presentations


Ads by Google