Experiment :3
IMAGE ENHANCEMENT BY SPATIAL FILTERING
AIM:
To perform image enhancement by spatial filtering.
SOFTWARE
MATLAB
THEORY:
In Spatial filtering, the filtering operations are performed directly on the pixels of
an image.
There are two types of spatial filters, linear and non linear filters. The mechanics
of spatial filtering is that it is the process which consists of simply moving the
filter mask from point to point in an image. At each point (x,y) the response of
the filter at that point is calculated using a predefined relationship. For linear
spatial filtering, the response is given by a sum of products of the filter
coefficients and the corresponding image pixels in the area spanned by the filter
mask. Smoothing filters are used for blurring and for noise reduction. The output
of a smoothing linear spatial filter is simply the average of the pixels contained in
the neighbourhood of the filter mask. These filters are called averaging or
lowpass filters.
Order statistics filters are non-linear spatial filters whose response is based on
ordering the pixels contained in the image area encompassed by the filter and
then replacing the value of the center pixel with the value determined by the
ranking result. Median filter replaces the value of a pixel with the median of the
graylevels in the neighbourhood of the pixel.
Program
% Average
i=imread('spine.tif');
imshow(i);
title('original image');
w=fspecial('average',[3 3]);
g=imfilter(i,w,'symmetric');
figure,
imshow(g,[])
title('Average');
%Gaussian
i=imread('spine.tif');
w=fspecial('gaussian',[3 3],0.5);
figure,
g=imfilter(i,w,'symmetric');
imshow(g,[])
title('Gaussian');
% Laplacian
i=imread('spine.tif');
w=fspecial('laplacian', 0.5);
g=imfilter(i,w,'symmetric');
figure,
imshow(g,[])
title('Laplacian');
%Sobel
i=imread('spine.tif');
w=fspecial('sobel');
g=imfilter(i,w,'symmetric');
figure,
imshow(g,[])
title('Sobel');
%Non linear order statistic filter
i=imread('spine.tif');
h=ordfilt2(i,1,ones(3,3));
h1=ordfilt2(i,3*3,ones(3,3));
h2=ordfilt2(i,median(1:3*3),ones(3,3));
subplot(2,2,1)
imshow(i);
title('original image');
subplot(2,2,2)
imshow(h,[]);
title('order statistic filter(1)');
subplot(2,2,3)
imshow(h1,[]);
title('order statistic filter(2)');
subplot(2,2,4)
imshow(h2,[]);
title('order statistic filter(3)');
%Median Filter
i=imread('spine.tif');
m=medfilt2(g,[3 3]);
figure,
imshow(m,[]);
title('Median');
Output