help to identify the mistake
Show older comments
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
1 Comment
Ameer Hamza
on 21 Apr 2020
What is the issue? Do you get any error?
Accepted Answer
More Answers (0)
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!