zoukankan      html  css  js  c++  java
  • matlab练习程序(zs图像细化)

    zseven.m

    function out=zseven(nbhd)
        s=sum(nbhd(:))-nbhd(5);
        temp1=(2<=s)&(s<=6);
        p=[nbhd(1) nbhd(4) nbhd(7) nbhd(8) nbhd(9) nbhd(6) nbhd(3) nbhd(2)];
        pp=[p(2:8) p(1)];
        xp=sum((1-p).*pp);
        temp2=(xp==1);
        prod1=nbhd(4)*nbhd(8)*nbhd(2);
        prod2=nbhd(4)*nbhd(6)*nbhd(2);
        temp3=(prod1==0)&(prod2==0);
        if temp1&temp2&temp3&nbhd(5)==1
             out=0;
        else
            out=nbhd(5);
        end;

    zsodd.m

    function out=zsodd(nbhd)
        s=sum(nbhd(:))-nbhd(5);
        temp1=(2<=s)&(s<=6);
        p=[nbhd(1) nbhd(4) nbhd(7) nbhd(8) nbhd(9) nbhd(6) nbhd(3) nbhd(2)];
        pp=[p(2:8) p(1)];
        xp=sum((1-p).*pp);
        temp2=(xp==1);
        prod1=nbhd(4)*nbhd(8)*nbhd(6);
        prod2=nbhd(8)*nbhd(6)*nbhd(2);
        temp3=(prod1==0)&(prod2==0);
        if temp1&temp2&temp3&nbhd(5)==1
             out=0;
        else
            out=nbhd(5);
        end;

    zs.m

    function out=zs(im)
    %
    %zs appises the Zhang-Suen skeletonization algorithm to image IM. IM must
    %be binary.
    %
    luteven=makelut('zseven',3);
    lutodd=makelut('zsodd',3);
    done=0;
    N=2;
    last=im;
    previous=applylut(last ,lutodd);
    current=applylut(previous,luteven);
    while done==0,
        if all(current(:)==last(:)),
            done=1;
        end
        N=N+1;
        last=previous;
        previous=current;
        if mod(N,2)==0,
            current=applylut(current,luteven);
        else
            current=applylut(current,lutodd);
        end;
    end;
    out=current;

    main.m

    % 从当前的工作文件夹中,彩色图像读入;
    im=imread('simonyuming.jpg');
    % 将彩色图像转换成灰度图像;
    imgray=rgb2gray(im);
    % 将灰度图像进行二值化处理,阈值设为128 
    %这句话的意思是生成一个新的数组(图像),
    %条件是:把im中的所有大于128的元素,
    %在新的数组中相应的位置设置成,其余的变成,这样就形成了
    %二值图像了.
    imb=imgray>128; 
    % 下面就可以调用细化函数了
    imthin=zs(imb); 
    % 显示原始图像(未细化前的图像)
    figure(1)
    imshow(imb) ; 
    % 显示结果图像(细化后的图像)
    figure(2) 
    imshow(imthin) ;

    纯搬运。

    参考:

    1.http://hi.baidu.com/simonyuee/blog/item/a02c744e3056bc0cb3de05e8.html

    2.http://blog.21ic.com/user1/6014/archives/2009/62725.html

  • 相关阅读:
    Python is 和 == 的区别, 编码和解码
    Python数据类型之字典
    Python中的基本数据类型之列表与元组初步了解
    Python中基本数据类型与对字符串处理的方法
    Python中的循环体
    Python的历史与基本知识入门
    web前端面试题库
    canvas绘图实现浏览器等待效果
    HTML5 Web Worker的使用
    思维题-方案数
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2521335.html
Copyright © 2011-2022 走看看