In: Electrical Engineering
Generate a noisy image by adding salt and pepper noise to a clean image (try to add moderate to low level of noise).
Now, investigate the effects of the following on the noisy image:
The filter size (e.g. 3´3 and 7´7) for the median filter.
Repeated application of a 3´3 median filter for several times
%matlab code is needed
Hello,
Please find
the answer attached as under. Please give a thumbs up
rating if you find the answer useful! Have a rocking day
ahead!
**** Matlab Code *****
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% median filtering for removing salt and pepper noise
% Read image into workspace
I = imread('eight.tif');
%Add salt and pepper noise.
J = imnoise(I,'salt & pepper',0.02);
%Use a median filter to filter out the noise.
K1 = medfilt2(J);
K2 = medfilt2(J,[7 7]);
K3 = medfilt2(J,[9 9]);
%Display all results
figure;
subplot(2,2,1);
imshow(J)
title('original image with noise')
subplot(2,2,2);
imshow(K1)
title('image filtered with 3x3')
subplot(2,2,3);
imshow(K2)
title('image filtered with 7x7')
subplot(2,2,4);
imshow(K3)
title('image filtered with 9x9')
%%%%%%%%%% Progressive filtering with 3x3 filter
figure;
subplot(2,2,1);
imshow(J)
title('original image with noise')
subplot(2,2,2);
imshow(K1)
title('image filtered with 3x3')
K4 = medfilt2(K1);
subplot(2,2,3);
imshow(K4)
title('image filtered with 3x3 twice')
K5 = medfilt2(K4);
subplot(2,2,4);
imshow(K5)
title('image filtered with 3x3 thrice')
**** End of Code ****
Output:
We see that in both the cases of filtering, the final image gets progressively blurred. However, the effect of blurring is more pronounced in the 7x7 and the 9x9 cases. The same also happens when the 3x3 filter is repeatedly applied. Noise removal is optimal in the 3x3 case.