CODE
clear all
clc
a = imread('cameraman.tif');
p = imnoise(a,'salt & pepper',0.02'); %Adding noise
q = double(p);
[row col] = size(q);
for i=2:1:row-1
for j=2:1:col-1
%To make a 3x3 mask into 1x9 mask
q1=[ q(i-1,j-1) q(i-1,j) q(i-1,j+1) q(i,j-1) q(i,j) q(i,j+1) q(i+1,j-1) q(i+1,j)
q(i+1,j+1) ];
q2=sort(q1);
median=q2(5); %The fifth value is the median
q3(i,j)=median;
end
end
figure(1)
imshow(uint8(p))
title('Image after ''Salt & Pepper'' Noise')
figure(2)
imshow(uint8(q3))
title('Image after cleaning the ''salt & pepper'' noise using ''Low pass Median Filtering'' technique')
No comments:
Post a Comment