code doe median filter.i am no able to get the final filtered output image.plz help me to rectify the mistake
clcclear allclose alli=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); endend%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); endendfigure,imshow(out); %show the final recovered image
Best Answer