All posts by M.Ganesh Sai

M. Ganesh Sai is the founder of MGS Leadership Consultants India. He is a Success Coach, Motivational Speaker and Author of five books including the award-winning book Success Can Be Yours, Short Stories to Share – Get Inspired, Smartness Guide – Success Tools for Students, Skills for Your Career Success: Touch Your Tipping Point and Soar Like Eagles! Success Tools For Freshers. His articles have been featured in various international journals including The Journal of Values-Based Leadership, USA http://scholar.valpo.edu/jvbl/vol7/iss1/10 Full Issue http://scholar.valpo.edu/jvbl/vol7/iss1/. He has been listed as one of the leading achievers around the world in Marquis Who's Who in the World in 2014. His areas of interest include Success, Leadership, Motivation, Career and Personality Development. He coined an innovating learning tool ‘Play and Learn’. Microsoft in Education featured his interview on Indian education in 'Daily Edventures': http://dailyedventures.com/index.php/2014/01/30/m-ganeshsai/ Testimonials by internationally acclaimed leadership gurus are located at the following link: http://speakerpedia.com/speakers/m-ganesh-sai. His LinkedIn URL: http://www.linkedin.com/pub/m-ganesh-sai-author/34/262/202 His Amazon URL: http://www.amazon.com/Skills-Your-Career-Success-Tipping/dp/935023808X/ref=sr_1_139?s=books&ie=UTF8&qid=1359113183&sr=1-139 His Facebook Page URL: https://www.facebook.com/pages/M-Ganesh-Sai/471536619627802 His YouTube channel URL: http://www.youtube.com/channel/UCl8A_Zx55ZRVn_2YR4i0eEQ He can be reached at mgshyd@gmail.com Follow him https://twitter.com/mganeshsai

Learn To Explore

Think Twice!

Advertisements

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

ganesh_NF_1_5_9_u-sorttic
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

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

Insertion Sort Code in Matlab 2-D

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

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

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

for i = 2:m1-1
for j = 2:n1-1
flg = 0;
n = size(b);
for l = 2:n;
key = y(l);
k = l-1;
while(k>0 && y(k)>key)
y(k+1) = y(k);
k = k-1;
y(k+1)=key;
end
end
if y(i,j) == 0 || y(i,j) == 255
flg = 1;
end
if flg == 0
if S(1) < y(i,j) && y(i,j) < S(5) && 0 < S(1) && S(9) < 255
y(i,j) = y(i,j);
end
else
if S(1) < S(5) && S(5) < S(9) && 0 < S(5) && S(5) < 255
y(i,j) = S(5);
end
if S(1) >= S(5) || S(5) >= S(9) || S(5) == 255 && S(5) == 0
y(i,j) = y(i,j-1);
end
end
end
end
y(1,:) = y(2,:);
y(R,:) = y(R-1,:);
y(:,1) = y(:,2);
y(:,C) = y(:,C-1);
b2=b1(ll+1:m-ll,ll+1:n-ll);
figure,imshow(b2);
toc

Pirate

Column Sorting Code with Best Result in Matlab(2-D)

clc, clear, close all;
tic

a=imread(‘cameraman.tif’); imshow(a);
nf=.5;
ws=3;
ll=floor(ws/2);

b=imnoise(a,’salt & pepper’,nf); % Generation of noisey input to algorithm
figure,imshow(b);

[m1 n1]=size(a);
b1=zeros(m1+ws-1);
b1=uint8(b1);
[m n]=size(b1);
b1(ll+1:m-ll,ll+1:n-ll)=b;
for i = 2:m-1
for j = 2:n-1
if(b1(i,j)<=0||b1(i,j)>=255)
y=b1(i-ll:i+ll,j-ll:j+ll);
p = sort(y(:,1:1));
q = sort(y(:,2:2));
r = sort(y(:,3:3));
b = [p,q,r];
S = sort(b(:));
flg = 1;
if S(1) < b1(i,j) && b1(i,j) < S(5) && 0 < S(1) && S(9) < 255
b1(i,j) = y(i,j);

else
b1(i,j) = S(5);
end
end
end
end

b2=b1(ll+1:m-ll,ll+1:n-ll);
figure,imshow(b2)
[psnr,mse]=psnr_mse_maxerr(a,b2);
display(psnr)
display(mse)
toc

cameraman_NF_2_4_8_U-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

Asprince Sorting Code in MATLAB

tic
clc
clear all
a=imread(‘lena_gray.tif’);
imshow(a)
nf=.5;
ws=7;
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;
%figure,imshow(b3)
for i=r+1:m-r
for j=r+1:n-r
t1=b1(i-r:i+r,j-r:j+r);
t2=sortrows(t1);
t2=sort(t1(1:end,1:end));
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)
[psnr,mse]=psnr_mse_maxerr(a,b2);
display(psnr);display(mse);
toc

Ascending Sort Code With Effective Result in MATLAB – M. Ganesh Sai

tic
clc
clear all
a=imread(‘lena_gray.tif’);
imshow(a)
nf=.4;
ws=3;
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(:));
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