Tag Archives: Bubble Sort

Bubble Sort in MATLAB

clc, clear, close all;
tic
a=imread(‘lena_gray.tif’);
nf=.5;
ws=3;

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

[m1 n1]=size(b);
ll=floor(ws/2); 
b1=zeros(m1+ws-1); % b1 is zero matrix of 514*514
b1=uint8(b1); % b1 is a unsign 8 bit
[m n]=size(b1);

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

for i=ll+1:m1-ll
for j=ll+1:n1-ll
f1=b1(i-ll:i+ll,j-ll:j+ll);
f=f1;
n=length(f);
g=size(f);
for k=1:g
for l=g-1:-1:k+1
if(f(l)<f(l+1))
tmp=f(l);
f(l)=f(l+1);
f(l+1)=tmp;
end
end
end
if (0<b1(i,j)&&b1(i,j)<255) %(0<t1(2,2)&&t1(2,2)<255)
else
for i1=9:-1:1 % for i1= (start= 5 : step= -1 : end=1)
if (0<f(i1)&&f(i1)<255) % if
b1(i,j)=f(i1);
break;
end
if (i1==1)
b1(i,j)=f(5);
end
end
end
end
end
[m n]=size(b1);
b2=b1(ll+1:m-ll,ll+1:n-ll); % Size of b2 is 512*512
figure,imshow(b2);
toc

Advertisements