THEORY:
Filtering is a technique for modifying or enhancing an image. Spatial domain
operation or filtering (the processed value for the current pixel processed value
for the current pixel depends on both itself and surrounding pixels). Hence Filtering
is a neighborhood operation, in which the value of any given pixel in the output
image is determined by applying some algorithm to the values of the pixels in the
neighborhood of the corresponding input pixel. A pixel's neighborhood is some set
of pixels, defined by their locations relative to that pixel.
Following steps are used to compute the output pixel at position (x,y):
1. Rotate the correlation kernel 180 degrees about its center element to create a
convolution kernel.
2. Slide the center element of the convolution kernel so that it lies on top of the
(x,y) element of A.
3. Multiply each weight in the rotated convolution kernel by the pixel of A
underneath.
4. Sum the individual products from step 3.
Types of filters:
Source Code:
Low pass filter
img = imread('cameraman.tif');
imgd = im2double(img); % imgd in [0,1]
f = ones(3,3)/9;
img1 = filter2(f, imgd);
subplot(121); imshow(img);
subplot(122); imshow(img1);
% As mentioned earlier, the low pass filter can be used denoising. Let's test it.
First, to make the
% input a little bit noisy, we spray some pepper and salt on the image, and then
apply the mean
% Extra Snippets
% Program for implementation of smoothing or averaging filter in spatial domain
I=imread('trees.tif');
subplot(2,2,1);
imshow(J);
title('original image');
f=ones(3,3)/9;
h=imfilter(I,f,'circular');
subplot(2,2,2);
imshow(h);
title('averaged image');
The above code has some effect on the salt and pepper noise but not much.
It just made them blurred. We can use Matlab's built-in median filter to improve the
resultant image.
I = imread('cameraman.tif');
J = imnoise(I,'salt & pepper',0.02);
K = medfilt2(J);
subplot(121);
imshow(J);
subplot(122);
imshow(K);
CONCLUSION:
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------