• 大小: 723 Bytes
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-10-16
  • 语言: Matlab
  • 标签: matlab  8领域  

资源简介

8领域边界跟踪 图像处理 matlab 完全原创 效果很好 欢迎下载

资源截图

代码片段和文件信息

function edge_follow(I)
%edge_follow(I)用以跟踪手的边界
%I为输入的二值图像文件名
%im_edge.bmp是提取的边沿图像

imbw=imread(I);
[MN]=size(imbw);
Itemp=zeros(M+2N+2); 
im_edge=Itemp;                                                     
Itemp(2:(M+1)2:(N+1))=imbw;


%im_edge = im_edge - imerode(im_edge[0 1 0 ; 1 1 1 ; 0 1 0]); %                  
%im_edge = bwmorph(im_edge‘thin‘Inf);                                               

[rowcol]=find(Itemp1);                                                      
x0=row;
y0=col;
ended=0;
MAJ=[6 6 0 0 2 2 4 4]; 
direction=4;

while(ended==0)
    found_next=0;      
     while(found_next==0)
        switch mod(direction8)
            case 0
                if (Itemp(row col+1)==1)
                    row=row;
                    col=col+1;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 1;
                if (Itemp(row+1 col+1)==1)
                    row=row+1;
                    col=col+1;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 2;
                if (Itemp(row+1 col)==1)
                    row=row+1;
                    col=col;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 3;
                if (Itemp(row+1 col-1)==1)
                    row=row+1;
                    col=col-1;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 4;
                if (Itemp(row col-1)==1)
                    row=row;
                    col=col-1;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 5;
                if (Itemp(row-1 col-1)==1)
                    row=row-1;
                    col=col-1;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 6;
                if (Itemp(row-1 col)==1)
                    row=row-1;
                    col=col;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
            case 7;
                if (Itemp(row-1 col+1)==1)
                    row=row-1;
                    col=col+1;
                    im_edge(rowcol)=1;
                    found_next=1;
                end;
                
        end

        if (found_next==0) direction=direction+1; end;
        
    end
    
    if(and((x0==row)(y0==col)))
        ended=1; 
    end;
    %direction = mod((direction+3)8)+1;
    direction = MAJ((mod(direction8)+1));
end
imwrite(im_edge‘im_edge.bmp‘‘bmp‘);
figure;
imshow(im_edge);

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

     文件       2857  2010-04-16 13:35  edge_follow.m

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

                 2857                    1


评论

共有 条评论