Spatial Filtering Spatial Filtering Spatial Filtering Filtering Example 1: 111 -121 -1-11 3 2 1 2 2 1 3 2 32 21 22 32 Rotate 1-1-1 12-1 111 Step 1 3 2 1 2 2 1 3 2 32 21 22 32 5 3 2 1 2 2 1 3 2 32 21 22 32 1-2-1 24-1 111 1-1-1 12-1 111 Step 2 3 2 1 2 2 1 3 2 32 21 22 32 45 3 2 1 2 2 1 3 2 32 21 22 32 3-1-2 24-2 111 1-1-1 12-1 111 Step 3 3 2 1 2 2 1 3 2 32 21 22 32 4 45 3 2 1 2 2 1 3 2 32 21 22 32 3-3-1 34-2 111 1-1-1 12-1 111 Step 4 3 2 1 2 2 1 3 2 32 21 22 32 4 4 -25 3 2 1 2 2 1 3 2 32 21 22 32 1-3-3 16-2 111 1-1-1 12-1 111 Step 5 3 2 1 2 2 1 3 2 32 21 22 32 4 4 9 -25 3 2 1 2 2 1 3 2 32 21 22 32 2-2-1 14-1 221 1-1-1 12-1 111 Step 6 3 2 1 2 2 1 3 2 32 21 22 32 6 4 4 9 -25 3 2 1 2 2 1 3 2 32 21 22 32 1-2-2 32-2 222 1-1-1 12-1 111 [...]... 0.0003 0 .011 0 0 .017 2 0 .011 0 0.0003 0 0.0003 0 .011 0 0 .017 2 0 .011 0 0.0003 0 linear spatial filtering linear spatial filtering im=imread('liftingbody.png'); im=imnoise(im,'gaussian'); h = fspecial('disk', 5); im1=imfilter(im,h); subplot(1, 2, 1); imshow(im); xlabel('original image','FontSize', 14) subplot(1, 2, 2) imshow(im1); xlabel('image after averaging filter','FontSize', 14) linear spatial filtering. .. 6 3 6 3 3 6 6 3 5 2 2 5 5 2 linear spatial filtering g = imfilter(f, w, filtering_ mode, boundary_options, size_options) w is the filter filtering mode= corr, conv boundary options=p, replicate, symmetric, circular size options=full, same Options for function imfilter linear spatial filtering w=fspecial(‘type’, parameters); linear spatial filtering linear spatial filtering h = fspecial(type) h = fspecial(type,... filter','FontSize', 14) linear spatial filtering h = fspecial('disk', radius) returns a circular averaging filter (pillbox) within the square matrix of side 2*radius+1 The default radius is 5 h = fspecial('disk', 3) h= 0 0.0003 0 .011 0 0 .017 2 0 .011 0 0.0003 0.0003 0.0245 0.0354 0.0354 0.0354 0.0245 0 .011 0 0.0354 0.0354 0.0354 0.0354 0.0354 0 .017 2 0.0354 0.0354 0.0354 0.0354 0.0354 0 .011 0 0.0354 0.0354 0.0354... it can be a scalar, in which case h is a square matrix The default value for hsize is [3 3] linear spatial filtering >>h = fspecial('average', 4) >>h = 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 linear spatial filtering linear spatial filtering %im=imread('rice.png'); %im = imread('coins.png'); im=imread('liftingbody.png'); %im = imread('peppers.png');... Linear Spatial Filtering using function imfilter Some small programs (Matlab code) demonstrates Linear Spatial Filtering using function imfilter kid=imread('kid02.jpg'); w=[1 1 1;1 -8 1;1 1 1]; C=imfilter(kid, w,'corr', 'replicate', 'same'); subplot(1,2,1);imshow(kid);title('Original','FontSize',20); subplot(1,2,2);imshow(4*C);title(mat2str(w),'FontSize',20); W= 1 1 1 1 −8 1 1 1 1 Linear Spatial. .. for n = 1+r:N-r for m = 1+r:M-r % Extract a window of size (2r+1)x(2r+1) around (m,n) w = x(m+(-r:r),n+(-r:r)); y(m,n)=sum(sum(w.*h)); end end subplot(1, 2, 1), imshow(x) subplot(1, 2, 2), imshow(y) Spatial Filtering Padarray function Generally: B = padarray(A,padsize,method,direction) B = padarray(A,padsize) pads an array A with zeros, where padsize defines the amount of padding to add in each dimension... w,'corr', 'replicate', 'same'); subplot(1,2,1);imshow(kid);title('Original','FontSize',20); subplot(1,2,2);imshow(4*C);title(mat2str(w),'FontSize',20); W= 1 1 1 1 −8 1 1 1 1 Linear Spatial Filtering . Spatial Filtering Spatial Filtering Spatial Filtering Filtering Example 1: 111 -121 -1-11 3 2 1 2 2 1 3 2 32 21 22 32 Rotate 1-1-1 12-1 111 Step. x(m+(-r:r),n+(-r:r)); y(m,n)=sum(sum(w.*h)); end end subplot(1, 2, 1), imshow(x) subplot(1, 2, 2), imshow(y) Spatial Filtering B = padarray(A,padsize) pads an array A with zeros, where padsize defines the amount