help to identify the mistake
2 views (last 30 days)
Show older comments
tresa joseph
on 21 Apr 2020
Edited: KALYAN ACHARJYA
on 21 Apr 2020
code doe median filter.i am no able to get the final filtered output image.plz help me to rectify the mistake
clc
clear all
close all
i=imread('peacock.jpg');
imshow(i);
i=imnoise(i,'salt & pepper',0.05);
figure,imshow(i)
p=input('Enter the size of kernel of median filter, (n for nxn matrix):');
pad=uint8(zeros(size(i)+2*(p-1)));
%loop for padding the zeros
for x=1:size(i,1)
for y=1:size(i,2)
pad(x+p-1,y+p-1)=i(x,y);
end
end
%loop for finding the median & replacing the central pixel
for i= 1:size(pad,1)-(p-1)
for j=1:size(pad,2)-(p-1)
kernel=uint8(ones((p-1)^2,1));
t=1;
for x=1:p-1
for y=1:p-1
kernel(t)=pad(i+x-1,j+y-1);
t=t+1;
end
end
filt=sort(kernel);
out(i,j)=filt(5);
end
end
figure,imshow(out); %show the final recovered image
Accepted Answer
KALYAN ACHARJYA
on 21 Apr 2020
Edited: KALYAN ACHARJYA
on 21 Apr 2020
Its works for my sample image, I have choosed n more than>3, like 5,7....
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!