www.pudn.com > ridge_extract.rar > forth_follow.asv, change:2007-05-08,size:4552b
function [ri,le_right,e_right,in]=forth_follow(startx,starty,I,D,i)
%---------------------
%向前跟踪
%---------------------
in=i;%即将要跟踪的脊线标号
overlap=0;%是否跟踪到重复的脊线标志位,‘0’表示没有重复,‘1’表示重复
end_right=zeros(1,2);%右终点坐标
ridge=zeros(size(I));%脊线轨迹矩阵
length_left=0;%左边脊线长度
length_right=0;%右边脊线长度
signal=0;%是否发生回退信号,‘1’表示没有发生
ridge(startx,starty)=i;
[r,c]=size(I);
startx,starty,ridge(startx,starty)%-----------------
pre_x=startx;
pre_y=starty;
p_x=startx;
p_y=starty;
next_x=0;
next_y=0;
section=zeros(3,2);
%正向跟踪
while 1
signal=0;
if p_y+1=c
section(2,2)=I(p_x,p_y+1);
else
section(2,2)=1;
end
if (p_x-1>=1)&(p_y+1=c)
section(1,2)=I(p_x-1,p_y+1);
else
section(1,2)=1;
end
if p_x-1>=1
section(1,1)=I(p_x-1,p_y);
else
section(1,1)=1;
end
if (p_x+1=r)&(p_y+1=c)
section(3,2)=I(p_x+1,p_y+1);
else
section(3,2)=1;
end
if (p_x+1)=r
section(3,1)=I(p_x+1,p_y);
else
section(3,1)=1;
end
section(2,1)=~I(p_x,p_y);
% section(1,1)=1;
while signal==0
[xn,yn,sn]=find(~section);
[rn,cn]=size(xn);
switch rn
case 0
[next_x,next_y]=five_ray(p_x,p_y,I,D,0);
if (next_x==0)&(next_y==0)
end_right(1)=p_x;
end_right(2)=p_y;
break;
end
case 1
next_x=p_x+xn-2;
next_y=p_y+yn-1;
otherwise
if (D(p_x,p_y)==1)&((p_y+1)=c)&(section(2,2)==0)
next_x=p_x;
next_y=p_y+1;
elseif (D(p_x,p_y)==2)&((p_y+1)=c)&((p_x-1)>=1)&(section(1,2)==0)
next_x=p_x-1;
next_y=p_y+1;
elseif (D(p_x,p_y)==3)&(((p_x-1)>=1)|(p_x+1=r))
if section(3,1)==0
next_x=p_x+1;
next_y=p_y;
elseif section(1,1)==0
next_x=p_x-1;
next_y=p_y;
end
elseif (D(p_x,p_y)==4)&((p_y+1)=c)&((p_x+1)=r)&(section(3,2)==0)
next_x=p_x+1;
next_y=p_y+1;
elseif section(3,2)==0%克服点方向错误,只要有邻接点就往下走
next_x=p_x+1;
next_y=p_y+1;
elseif section(2,2)==0
next_x=p_x;
next_y=p_y+1;
elseif section(1,2)==0
next_x=p_x-1;
next_y=p_y+1;
elseif section(3,1)==0
next_x=p_x+1;
next_y=p_y;
elseif section(1,1)==0
next_x=p_x-1;
next_y=p_y;
else
[next_x,next_y]=five_ray(p_x,p_y,I,D,0);
if (next_x==0)&(next_y==0)
end_right(1)=p_x;
end_right(2)=p_y;
break;
end
end
end %The end of 'switch'
if (next_x==pre_x)&(next_y==pre_y)
signal=0;
section(2+next_x-p_x,1+next_y-p_y)=1;
else
signal=1;
end
end
if (next_x==0)&(next_y==0)
break;
end
if (ridge(next_x,next_y)>0)&(ridge(next_x,next_y)<i)%下一个点在已经跟踪过的脊线上
for ik=1:r
for jk=1:c
if ridge(ik,jk)==i
i=ridge(next_x,next_y);
ridge(ik,jk)=i;
ik,jk,ridge(ik,jk)%-------------------
end
end
end
if overlap==0 %若在这之前没有发生过重复的情况,即将要跟踪的脊线标号减1
in=in-1;
end
%当前跟踪的脊线对该部分的脊线长不影响
% if flag==0 %正向跟踪
length_right=0;
% else %反向跟踪
% length_left=0;
% end
overlap=1;
else
ridge(next_x,next_y)=i;
next_x,next_y,ridge(next_x,next_y)%--------------------
% if flag==0 %正向跟踪
length_right=length_right+1;
% else %反向跟踪
% length_left=length_left+1;
% end
end
pre_x=p_x;
pre_y=p_y;
p_x=next_x;
p_y=next_y;
end
ri=ridge;
le_right=length_right;
e_right=end_right;