MATLAB exercise program (ZS image refinement)

Source: Internet
Author: User

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

% From the current work folder, the color image is read into the mirror im1_imread('simonyuming.jpg '); % the color image is converted into a grayscale image; imgray = rgb2gray (IM); % The grayscale image is binarization, the threshold value is set to 128%, which means to generate a new array (image). % The condition is that all elements greater than 128 in IM are taken, % in the new array, the corresponding position is set to 1, and the rest is changed to 0, forming a binary image. IMB = imgray> 128; % You can call the refinement function below imthin = ZS (IMB); % display original image (image before refinement) figure (1) imshow (IMB); % display result image (refined image) figure (2) imshow (imthin );

Pure handling.

Refer:

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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.