Digital Image Processing Chapter 3 Neighbourhood Processing

Published on Slideshow
Static slideshow
Download PDF version
Download PDF version
Embed video
Share video
Ask about this video

Scene 1 (0s)

Digital Image Processing Chapter 3 Neighbourhood Processing.

Scene 2 (17s)

Neighbourhood Processing. We have seen in chapter 2 that an image can be modified by applying a particular function to each pixel value. Neighbourhood processing may be considered as an extension of this, where a function is applied to a neighbourhood of each pixel. The idea is to move a “mask”: a rectangle (usually with sides of odd length) or other shape over the given image. As we do this, we create a new image whose pixels have grey values calculated from the grey values under the mask. The combination of mask and function is called a filter. If the function by which the new grey value is calculated is a linear function of all the grey values in the mask, then the filter is called a linear filter. A linear filter can be implemented by multiplying all elements in the mask by corresponding elements in the neighbourhood , and adding up all these products..

Scene 3 (3m 27s)

Spatial filtering thus requires three steps: position the mask over the current pixel, Form all products of filter elements with the corresponding elements of the neighbourhood . Add up all the products. This must be repeated for every pixel in the image. Allied to spatial filtering is spatial convolution. The method for performing a convolution is the same as that for filtering, except that the filter must be rotated by 180 degree before multiplying and adding. Note also that in practice, most filter masks are rotationally symmetric, so that spatial filtering and spatial convolution will produce the same output..

Scene 4 (5m 40s)

3/13/2022. 4.

Scene 5 (6m 8s)

Smoothing filters are used for blurring and for noise reduction.

Scene 6 (8m 49s)

4/8/2022. 6. Two Smoothing Averaging Filter Masks.

Scene 7 (13m 49s)

Some Matlab Matrix generation function: >> magic(n) is an N-by-N matrix constructed from the integers >> eye(N) is an N-by-N matrix with 1's on the diagonal and zeros elsewhere. eye(M,N) is an M-by-N matrix. >> ones(N) is an N-by-N matrix of ones. ones(M,N) is an M-by-N matrix of ones. >> zeros(N) is an N-by-N matrix of zeros. zeros(M,N) is an M-by-N matrix of zeros. >> randn (N) returns an N-by-N matrix containing random values drawn from the standard normal distribution. randn (M,N) returns an M-by-N matrix. >> randi (IMAX,N) returns an N-by-N matrix containing random integer values drawn from the discrete uniform distribution on 1:IMAX. randi (IMAX,M,N) returns an M-by-N matrix..

Scene 8 (16m 42s)

Example of Spatial filtering. 3/13/2022. 8.

Scene 9 (19m 42s)

Edges of the image. Ignore the edges. That is, the mask is only applied to those pixels in the image for with the mask will lie fully within the image. This means all pixels except for the edges, and results in an output image which is smaller than the original. If the mask is very large, a significant amount of information may be lost by this method. We applied this method in our example above. “Pad” with zeros. We assume that all necessary values outside the image are zero. This gives us all values to work with, and will return an output image of the same size as the original, but may have the effect of introducing unwanted artifacts (for example, edges) around the image..

Scene 10 (22m 30s)

Filtering in Matlab. The filter2 function does the job of linear filtering for us; its use is >> filter2( filter,image,shape ) and the result is a matrix of data type double . The parameter shape is optional, it describes the method for dealing with the edges: >>filter2( filter,image,’same ’) is the default; it produces a matrix of equal size to the original image matrix. It uses zero padding. >>filter2( filter,image,’valid ’) applies the mask only to “inside” pixels. The result will always be smaller than the original:.

Scene 11 (24m 4s)

3/13/2022. 11.

Scene 12 (25m 53s)

3/13/2022. 12.

Scene 13 (27m 12s)

3/13/2022. 13. >> filter2( filter,image,’full ’) returns a result larger than the original; it does this by padding with zero, and applying the filter at all places on and around the image where the mask intersects the image matrix..

Scene 14 (28m 26s)

3/13/2022. 14. We can create our filters by hand, or by using the fspecial function ; this has many options which makes for easy creation of many different filters. We shall use the average option, which produces averaging filters of given size; thus >> fspecial (’average’,[5,7]) will return an averaging filter of size 5*7 more simply >> fspecial (’average’,11) will return an averaging filter of size 11*11. If we leave out the final number or vector, the averaging filter is returned. >> c= imread (’ cameraman.tif ’); >> f1= fspecial (’average’); >> cf1=filter2(f1,c); >> figure,imshow (c), figure,imshow (cf1/255).

Scene 15 (30m 59s)

3/13/2022. 15. (a) Original image (c) Using a 9 X 9 filter (b) Average filtering (d) Using a 25 x 25 filter.

Scene 16 (31m 47s)

Frequencies; low and high pass filters. The frequencies of an image are a measure of the amount by which grey values change with distance. High frequency components are characterized by large changes in grey values over small distances; example of high frequency components are edges and noise. Low frequency components, on the other hand, are parts of the image characterized by little change in the grey values. These may include backgrounds, skin textures. high pass filter if it “passes over” the high frequency components, and reduces or eliminates low frequency components, low pass filter if it “passes over” the low frequency components, and reduces or eliminates high frequency components,.

Scene 17 (35m 42s)

3/13/2022. 17. is a high pass filter. We note that the sum of the coefficients (that is, the sum of all e elements in the matrix), in the high pass filter is zero. This means that in a low frequency part of an image, where the grey values are similar, the result of using this filter is that the corresponding grey values in the new image will be close to zero..

Scene 18 (37m 58s)

3/13/2022. 18. High pass filter mask in Matlab. imshow ( cf /255) >>cf1=filter2(f1,c); >> figure,imshow (cf1/255).

Scene 19 (39m 45s)

(a) Laplacian filter (b) Laplacian of Gaussian ("log") filtering.

Scene 20 (40m 35s)

Clip values. We apply the following thresholding type operation to the grey values produced by the filter to obtain a displayable value.

Scene 21 (42m 18s)

3/13/2022. 21. Values outside the range 0–255. Scaling transformation. Suppose the lowest grey value produced by the filter if gL and the highest value is gH . We can transform all values in the range gL – gH to the range 0–255 by the linear transformation illustrated below:.

Scene 22 (43m 43s)

3/13/2022. 22.

Scene 23 (44m 28s)

Edge sharpening. Spatial filtering can be used to make edges in an image slightly sharper and crisper, which generally results in an image more pleasing to the human eye. The operation is variously called “edge enhancement”, “edge crispening”, or “unsharp masking”. Unsharp masking The idea of unsharp masking is to subtract a scaled “unsharp” version of the image from the original. In practice, we can achieve this affect by subtracting a scaled blurred image from the original..

Scene 24 (45m 51s)

Edge sharpening. 3/13/2022. 24. >> f= fspecial (’average’); >> xf =filter2( f,x ); >> xu=double(x)- xf /1.5 >> imshow (xu/70) The last command scales the result so that imshow displays an appropriate image; the value may need to be adjusted according to the input image..

Scene 25 (48m 27s)

Non-linear filters. A non-linear filter is obtained by a non-linear function of the greyscale values in the mask. Simple examples are the maximum filter, which has as its output the maximum value under the mask, and the corresponding minimum filter, which has as its output the minimum value under the mask. Both the maximum and minimum filters are examples of rank-order filters. In such a filter, the elements under the mask are ordered, and a particular value returned as output. So if the values are given in increasing order, the minimum filter is a rank-order filter for which the first element is returned, and the maximum filter is a rank-order filter for which the last element is returned. >> cmax = nlfilter (c,[3,3],’max(x(:))’); The nlfilter function requires three arguments: the image matrix, the size of the filter, and the function to be applied. >> cmin = nlfilter (c,[3,3],’min(x(:))’);.

Scene 26 (51m 32s)

(a) Using a maximum filter (b) Using a minimum filter.

Scene 27 (52m 29s)

>> cmax =ordfilt2(c,9,ones(3,3)); and the minimum filter can be applied with >> cmin =ordfilt2(c,1,ones(3,3)); We could apply the median filter with >> cmed =ordfilt2(c,5,ones(3,3)); However, the median filter has its own command , medfilt2,.

Scene 28 (55m 21s)

4/8/2022. 28. Example: Use of Median Filtering for Noise Reduction.

Scene 29 (57m 45s)

thanks. 3/13/2022. 29.