Merge Sort Code in 2-D Image Processing – M. Ganesh Sai

tic
clc
clear all
close all
a=imread(‘cameraman.tif’);
imshow(a)
nf=.1;
ws=3;
b=imnoise(a,’salt & pepper’,nf);
figure,imshow(b)
[m1 n1]=size(a);
r=floor(ws/2);
b1=128*ones(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);
t1=t1(:);
t1=t1′;
merged=mergeSort1(t1);
pmin=merged(1);
pmax=merged(end);
pmed=merged(ceil(length(t1)/2));
if pmin<b1(i,j)<pmax&&pmin>0&&pmax<255
b1(i,j)=b1(i,j);
end
if pmin<pmed<pmax || (0<pmed && pmed<255)
b1(i,j)=pmed;
end
if pmed==0 || pmed==255
pmed=b1(i,j-1);
end
if b1(i,j)==0 || b1(i,j)==255
b1(i,j)=b1(i,j-1);
end
end
end
b2=b1(r+1:m-r,r+1:n-r);
figure,imshow(b2)
[psnr,mse]=psnr_mse_maxerr(a,b2);
display(psnr);
toc

cameraman_NF_2_4_8_U-sort

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s