Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Image Processing. Introduction Mask moving (or convolution) A rectangle (usually with sides of odd length) or other shape over the given image.

Similar presentations


Presentation on theme: "Digital Image Processing. Introduction Mask moving (or convolution) A rectangle (usually with sides of odd length) or other shape over the given image."— Presentation transcript:

1 Digital Image Processing

2 Introduction Mask moving (or convolution) A rectangle (usually with sides of odd length) or other shape over the given image 2

3 Mask & Overlapping Pixel Values 3 a 3X5 mask corresponding pixel values

4 Spatial Filtering 4 1.Position mask over current pixel 2.Form all products of filter elements with the corresponding elements of the neighborhood 3.Add all the product 4.Repeat for every pixel in image

5 Spatial Convolution Similar to spatial filtering, except.. The filter must be rotated by 180° before multiplying and adding Or, equivalently, The rationale of “convolution” will become apparent in view of Fourier Transform 5

6 Mean Filter Example Given a 3×3 mask, take the average of all nine values within the mask 6 The result of filtering x with 3×3 averaging filter

7 Mask Notation It is convenient to describe a linear filter simply in terms of the coefficients of all the gray values of pixels within the mask The averaging filter The other filter example 7 Ch5-p.91-92

8 Mask on the Edge What happens at the edge of the image, where the mask partly falls outside the image? There are a number of different approaches to dealing with this problem Ignore the edges (like the example shown previously) Pad with zeros Mirroring 8

9 Filtering in M ATLAB filter2(filter, image, shape) The result is a matrix of data type “double” shape is optional; it describes the method for dealing with the edges ‘same’ – pad with zeros ‘valid’ – ignore the edges ‘full’ – pad with zeros and applying the filter at all places on and around the image where the mask intersects the image matrix imfilter(image,filter,options..) More advanced image filtering function 9

10 Filtering Examples in M ATLAB (1/2) 10 >> x = uint8(10*magic(5)) >> a = ones(3,3)/9 >> filter2(a,x,'same') >> filter2(a,x,'valid')

11 Filtering Examples in M ATLAB (2/2) filter2 provides no mirroring option Mirroring can be realized by 11 >> filter2(a,x,'full') >> D = floor(size(a)/2) >> wr=D(1);wc=D(2); % get half of the mask size >> m_x=[x(wr:-1:1,:);x;x(end:-1:end-(wr-1),:)]% additional mirrored-rows >> m_x=[m_x(:,wc:-1:1),m_x,m_x(:,end:-1:end-(wc-1))]; % additional mirrored columns >> filter2(a,m_x,'valid')

12 Pre-cooked Filtering in M ATLAB: fspecial() 12 I = imread('cameraman.tif'); subplot(2,2,1);imshow(I);title('Original Image'); H = fspecial('motion',20,45); MotionBlur = imfilter(I,H,'replicate'); subplot(2,2,2);imshow(MotionBlur);title('Motion Blurred Image'); H = fspecial('disk',10); blurred = imfilter(I,H,'replicate'); subplot(2,2,3);imshow(blurred);title('Blurred Image'); H = fspecial('unsharp'); sharpened = imfilter(I,H,'replicate'); subplot(2,2,4);imshow(sharpened);title('Sharpened Image');

13 Low- and High-Pass Filters (1/2) Frequencies of an image are a measure of the amount by which gray values change with distance High-pass filter (left) Low-pass filter (right) 13 Ch5-p.98 >> f = fspecial('laplacian') >> cf = imfilter(c,f); >> f1 = fspecial('log') % Laplacian of Gaussian >> cf1 = imfilter(c,f1);

14 Low- and High-Pass Filters (2/2) Values outside [0,255] range Make negative value positive Clip values scaling transformation 14 >> f2 = [1 -2 1; ; ]; >> cf2 = filter2(f2,c); >> figure, imshow(mat2gray(cf2)); >> % scaling transformation >> maxcf2 = max(cf2(:)); >> mincf2 = min(cf2(:)); >> cf2g = (cf2-mincf2)/(maxcf2-mincf2); >> figure, imshow(cf2/60);

15 Gaussian Filters (1/2) 15 Ch5-p.103 >> a=50;s=3; >> g=fspecial('gaussian',[a a],s); >> surf(1:a,1:a,g) >> s = 9; >> g2 = fspecial('gaussian',[a a],s); >> figure, surf(1:a,1:a,g2)

16 Gaussian Filters (2/2) 16 >> c = imread('cameraman.tif'); >> g1 = fspecial('gaussian',[5 5]); >> g2 = fspecial('gaussian',[5 5],2); >> g3 = fspecial('gaussian',[11 11],1); >> g4 = fspecial('gaussian',[11 11],5); >> imshow(filter2(g1,c)/256); >> figure, imshow(filter2(g2,c)/256); >> figure, imshow(filter2(g3,c)/256); >> figure, imshow(filter2(g4,c)/256); g1g2 g3 g4

17 Scheme for Sharpening Masking 17 Ch5-p.106 >> c = imread(‘cameraman.tif’); >> f = fspecial('average'); >> xf = filter2(f,c); >> xu = double(c)-xf/1.5; >> imshow(xu/70);

18 >> p = imread('pelicans.tif'); >> u = fspecial('unsharp',0.5); >> pu = filter2(u,p); >> imshow(p), figure, imshow(pu/255); Unsharp Masking The unsharp option of fspecial produces such filters 18 α = 0.5 Ch5-p.108

19 High-Boost Filtering Allied to unsharp masking filters are the high- boost filters where A is an amplification factor If A = 1, then the high-boost filter becomes an ordinary high-pass filter 19 >> id = [0 0 0;0 1 0; 0 0 0]; >> f = fspecial('average'); >> hb1 = 3*id-2*f; >> hb2 = 1.25*id-0.25*f; >> x1 = filter2(hb1,p); >> x2 = filter2(hb2,p); >> figure, imshow(x1/255); >> figure, imshow(x2/255);

20 Nonlinear Filters Maximum filter Minimum filter 20 Ch5-p.112 >> cmax = nlfilter(c,[3 3],'max(x(:))'); >> cmin = nlfilter(c,[3 3],'min(x(:))'); >> figure, imshow(cmax); >> figure, imshow(cmin);

21 Region of Interest Processing 21 Ch5-p.115 >> ig = imread('iguana.tif'); >> roi = roipoly(ig,[ ],[ ]); >> figure, imshow(ig); >> figure, imshow(roi); >> roi_2 = roipoly(ig); % interactively select ROI

22 Region of Interest Filtering 22 Ch5-p.116 >> a = fspecial('average',[15 15]); >> iga = roifilt2(a,ig,roi); >> imshow(iga); >> u = fspecial('unsharp'); >> igu = roifilt2(u,ig,roi); >> figure, imshow(igu); >> L = fspecial('log'); >> igl = roifilt2(L,ig,roi); >> figure, imshow(igl); iga: average filtering igl: Laplacian of Gaussianigu: unsharp masking


Download ppt "Digital Image Processing. Introduction Mask moving (or convolution) A rectangle (usually with sides of odd length) or other shape over the given image."

Similar presentations


Ads by Google