tic

clc;

a=imread(‘lena_gray.tif’);

imshow(a)

nf=.9;

ws=9;

b=imnoise(a,’salt & pepper’,nf);

figure,imshow(b)

[m1 n1]=size(a);

r=floor(ws/2);

b1=zeros(m1+ws-1);

b1=uint8(b1);

[m n]=size(b1);

b1(r+1:m-r,r+1:n-r)=b;

for i=r+1:m-r

for j=r+1:n-r

t1=b1(i-r:i+r,j-r:j+r);

t2=sort(t1,1);

t2=sort(t2,2);

t2=t2′;

t2=t2(:);

t2=t2′;

le=length(t2);

len=ceil(le/2);

if (0<t1(r+1,r+1)&&t1(r+1,r+1)<255)

else

if t1(r+1,r+1)==255

for i1=len:-1:1

if (0<t2(i1)&&t2(i1)<255)

b1(i,j)=t2(i1);

break;

end

if (i1==1)

b1(i,j)=t2(len);

end

end

elseif t1(r+1,r+1)==0

for i1=len:le

if (0<t2(i1)&&t2(i1)<255)

b1(i,j)=t2(i1);

break;

end

if (i1==le)

b1(i,j)=t2(len);

end

end

end

end

end

end

b2=b1(r+1:m-r,r+1:n-r);

figure,imshow(b2)

toc

# ModeShift Sorting Technique Code In Matlab With Best Result- M. Ganesh Sai

Advertisements