Presentation is loading. Please wait.

Presentation is loading. Please wait.

Filtering in the Spatial Domain Filtering the spatial domain is achieved by convolution Qualitatively: Slide the filter to each position, x, then sum up.

Similar presentations


Presentation on theme: "Filtering in the Spatial Domain Filtering the spatial domain is achieved by convolution Qualitatively: Slide the filter to each position, x, then sum up."— Presentation transcript:

1 Filtering in the Spatial Domain Filtering the spatial domain is achieved by convolution Qualitatively: Slide the filter to each position, x, then sum up the function multiplied by the filter at that position

2 Convolution Example

3 Convolution Theorem Convolution in the spatial domain is the same as multiplication in the frequency domain –Take a function, f, and compute its Fourier transform, F –Take a filter, g, and compute its Fourier transform, G –Compute H=F  G –Take the inverse Fourier transform of H, to get h –Then h=f  g Multiplication in the spatial domain is the same as convolution in the frequency domain

4 Filtering Images Work in the discrete spatial domain Convert the filter into a matrix, the filter mask Move the matrix over each point in the image, multiply the entries by the pixels below, then sum –eg 3x3 box filter –averages

5 filter2(filter,image,shape) filter2(filter,image,'same') is the default; it produces a matrix of equal size to the original image matrix. filter2(filter,image,'valid') applies the mask only to inside pixels. filter2(filter,image,'full') returns a result larger than the original; it does this by padding with zero, and applying the lter at all places on and around the image where the mask intersects the image matrix.

6 fspecial function; this has many options which makes for easy creation of many different filters. fspecial('average',[5,7]) will return an averaging filter of size 5x7 fspecial('average',11) will return an averaging filter of size 11x11 If we leave out the final number or vector, the 3 x3 averaging filter is returned.

7 c=imread('cameraman.tif'); f1=fspecial('average'); cf1=filter2(f1,c); figure,imshow(c),figure,imshow(cf1/255)

8 Using a 9x9 filter Using a 25x25 filter c=imread('cameraman.tif'); f9=fspecial('average', 9); cf9=filter2(f9,c); figure,imshow(c),figure,imshow(cf9/255) f25=fspecial('average', 25); cf25=filter2(f25,c); figure,imshow(c),figure,imshow(cf25/255)

9 f=fspecial('laplacian') f = 0.1667 0.6667 0.1667 0.6667 -3.3333 0.6667 0.1667 0.6667 0.1667 >> cf=filter2(f,c); imshow(cf/100)

10 Laplacian of Gaussian (log) Filter f1=fspecial('log') f1 = 0.0448 0.0468 0.0564 0.0468 0.0448 0.0468 0.3167 0.7146 0.3167 0.0468 0.0564 0.7146 -4.9048 0.7146 0.0564 0.0468 0.3167 0.7146 0.3167 0.0468 0.0448 0.0468 0.0564 0.0468 0.0448 >> cf1=filter2(f1,c); figure,imshow(cf1/100) In each case, the sum of all the lter elements is zero.

11 cf1=filter2(f1,c); figure,imshow(cf1/100) >> f2=[1 -2 1;-2 4 -2;1 -2 1]; cf2=filter2(f2,c); >> figure,imshow(mat2gray(cf2)); mat2gray function automatically scales the matrix elements to displayable values

12 maxcf2=max(cf2(:)); mincf2=min(cf2(:)); f2g=(cf2-mincf2)/(maxcf2-mincf2); >> imshow(cf2g) >> figure,imshow(cf2/60) We can generally obtain a better result by dividing the result of the filtering by a constant before displaying it:

13 a=50; s=3; g=fspecial('gaussian', [a a], s); surf(1:a, 1:a, g)

14 s=9; >> g2=fspecial('gaussian', [a a], s); >> figure, surf(1:a, 1:a, g2)

15 Edge sharpening

16 p=imread('pelicans.tif'); u=fspecial('unsharp',0.5); pu=filter2(u,p); imshow(p),figure,imshow(pu/255)

17 Non-linear Filters maximum filter, which has as its output the maximum value minimum filter, which has as its output the minimum value rank-order filters. In such a filter, the elements under the mask are ordered Colfilt function, which rearranges the image into columns first. median filter, which takes the central value of the ordered list.

18 geometric mean lter


Download ppt "Filtering in the Spatial Domain Filtering the spatial domain is achieved by convolution Qualitatively: Slide the filter to each position, x, then sum up."

Similar presentations


Ads by Google