Freeman chain code algorithm code

Sat Jan 26, 2013 7:28 pm

Simple and easy freeman Chain Code algorithm code implementation , This implementation is used to detecting edges in binary images ( 0's,1's pixels), this code start by searching the binary image until it finds a 0 (black pixel).

freeman.m
matlab code
function []=freeman()
clc
m=imread('C:\Documents and Settings\Desktop\msi.bmp');

[h w d]=size(m);
h;
w;
d;
m
row=0;
col=0;
for i=w:-1:1 % column
for j=1:1:h % row
% m(j,i)
if(m(j,i)==0)
row=j;
col=i;
break;
end
end
end


m(row,col);
oldrow=row;
oldcol=col;
newrow=-1;
newcol=-1;
%while (row ~=newrow & col ~= newcol )
for i=1:300;

if(checkones(m,oldrow,oldcol)==1)%up 1
%your up is 1
if(m(oldrow,oldcol+1)==1)%righ 1
if(m(oldrow+1,oldcol)==1)%down 1
break;
else
newrow=oldrow+1;
newcol=oldcol;
end
else
newrow=oldrow;
newcol=oldcol+1;

end


else% your up is 0
if(m(oldrow,oldcol+1)==1)%down
newrow=oldrow+1;
newcol=oldcol;
else if(m(oldrow,oldcol+1)==0 &m(oldrow,oldcol-1)~=1)% rigth
newrow=oldrow;
newcol=oldcol+1;
else if(m(oldrow,oldcol-1)==1)% up
newrow=oldrow-1;
newcol=oldcol;
end
end

oldrow=newrow;
oldcol=newcol;
newrow
newcol

end



checkones.m
matlab code
function [c]=checkones(m,row,col)


c=0;
if(row==1)
c=1
else
if(m(row-1,col)==1)

c=1 ;

end
end


return ;




  Related Posts  to : Freeman chain code algorithm code
 apriori algorithm c code     -  
 apriori algorithm java code     -  
 java code for decision tree algorithm     -  
 LZW data compression-decompression algorithm java code     -  
 quicksort algorithm implementation java code- array sorting     -  
 balloon sort algorithm C++ implementation code-sorting array     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 i want code for connecting mobile and pc can u send me code     -  
 asking for code     -  
 code     -  

Topic Tags

Matlab Algorithms