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

 Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 21 de Abr. de 2020
Editada: KALYAN ACHARJYA el 21 de Abr. de 2020

0 votos

Its works for my sample image, I have choosed n more than>3, like 5,7....

Más respuestas (0)

Categorías

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 21 de Abr. de 2020

Editada:

el 21 de Abr. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by