资源简介

用matlab实现的链码提取算法。做项目时用到的,久寻不获,于是自己动手写了一个。希望对大家有所帮助。
需要把三个文件放在一个工作目录下。主函数是listcode,需要调用getcode和searchtip函数。

资源截图

代码片段和文件信息

%此函数用来根据一个已知点来提取以该点为端点的特征线的链码
%im为输入二值图像x0y0为端点坐标
function result=getcode(imx0y0)
[m n]=size(im);
points(1)=x0;   %用points记录所有链码起始点的位置
points(2)=y0;
next=1;    %用来判断是否结束对当前链码的搜索
number=1;  %用来记录当前链码以搜索点的数量
list=[];
list(number)=0;
x=x0;
y=y0;
%每当搜索到一个起始点,搜索其周围点,追寻链码轨迹
while(next==1)
    if(x<=0|x>m|y<=0|y>n)    %如果链码当前点已到达边界,则停止搜索
        next=0;
    else
        im(xy)=0;       %把已搜索过的点值置零,以免重复搜索
        
        %按照方向表中从1到8的顺序检索当前点周围是否存在非0点
        if(im(xy+1)==1)
            list(number)=4;
            x=x;
            y=y+1;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)     %判断是否回到起始点,若是则当前特征线链码提取结束
                next=0;
            end
        elseif(im(x+1y)==1)
            list(number)=6;
            x=x+1;
            y=y;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)
                next=0;
            end
        elseif(im(xy-1)==1)
            list(number)=8;
            x=x;
            y=y-1;
            x1=x;
            y1=y;
            number=number+1;
            if(x==x0&y==y0)
                next=0;
            end
        elseif(im(x-1y)==1)
            list(number)=2;
            x=x-1;
            y=y;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)
                next=0;
            end
        elseif(im(x+1y+1)==1)
            list(number)=5;
            x=x+1;
            y=y+1;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)
                next=0;
            end
        elseif(im(x+1y-1)==1)
            list(number)=7;
            x=x+1;
            y=y-1;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)
                next=0;
            end
        elseif(im(x-1y-1)==1)
            list(number)=1;
            x=x-1;
            y=y-1;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)
                next=0;
            end
        elseif(im(x-1y+1)==1)
            list(number)=3;
            x=x-1;
            y=y+1;
            x1=x;
            y1=y;
            number=1+number;
            if(x==x0&y==y0)
                next=0;
            end
        else
            next=0;
        end
    end
end
result=[x0 y0 x1 y1 list(:)‘];
end

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2690  2008-12-04 10:38  getcode.m

     文件       2106  2008-12-04 10:37  searchtip.m

     文件       4627  2008-12-04 10:43  listcode.m

----------- ---------  ---------- -----  ----

                 9423                    3


评论

共有 条评论