{"id":6702,"date":"2024-07-31T09:01:01","date_gmt":"2024-07-31T01:01:01","guid":{"rendered":""},"modified":"2024-07-31T09:01:01","modified_gmt":"2024-07-31T01:01:01","slug":"\u7ec6\u5316\u7b97\u6cd5matlab","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6702.html","title":{"rendered":"\u7ec6\u5316\u7b97\u6cd5matlab"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u6700\u7b80\u5355\u7684\u65b9\u6cd5<\/h2>\n

\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u7528matlab\u81ea\u5e26\u7684\u51fd\u6570\uff1a
BW2 = bwmorph(BW,'thin',n);<\/code>
n\u662f\u8981\u7ec6\u5316\u8fed\u4ee3\u7684\u6b21\u6570\uff0c\u4e5f\u53ef\u4ee5\u662fInf(\u6ca1\u6709\u5f15\u53f7)\u3002Inf\u8868\u793a\u7b97\u6cd5\u4f1a\u4e00\u76f4\u8fed\u4ee3\u76f4\u5230\u56fe\u50cf\u4e0d\u518d\u6539\u53d8\u3002
\u7b97\u6cd5\u539f\u7406\u53c2\u8003 [1]\u3002<\/p>\n

\u7a0d\u5fae\u590d\u6742\u70b9\u7684\u65b9\u6cd5<\/h2>\n

Zhang-Suen\u7b97\u6cd5
\u539f\u7406\u7b80\u4ecb\uff1ahttp:\/\/www.cnblogs.com\/mikewolf2002\/p\/3321732.html
\u7b97\u6cd5\u5b9e\u73b0\uff1ahttp:\/\/www.chinabaike.com\/t\/9642\/2014\/0624\/2547871.html
\u5c06\u4e0b\u5217\u4e09\u4e2am\u6587\u4ef6\u548c\u4e3bm\u6587\u4ef6\u653e\u5230\u4e00\u8d77\uff0c\u4e3bm\u6587\u4ef6\u8fd9\u6837\u8c03\u7528:BW2=zs(BW1);<\/code>
zs.m<\/p>\n

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

zseven.m<\/p>\n

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

zsodd.m<\/p>\n

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

\u81ea\u5df1\u6298\u817e\u7684\u8fc7\u7a0b<\/h2>\n

\u53c2\u8003[2]\u4e2d\u9aa8\u67b6\u5316\u7684\u7b97\u6cd5\uff0c\u4e0d\u77e5\u9053\u662f\u7b97\u6cd5\u5199\u9519\u4e86\uff0c\u8fd8\u662f\u672c\u6765\u8bba\u6587\u5c31\u6ca1\u6709\u8bba\u8ff0\u6e05\u695a\uff0c\u603b\u662f\u4f1a\u628a\u5de6\u4e0a\u89d2\u7ed9\u5f04\u65ad\uff0c\u5148\u8bb0\u5728\u4e0b\u9762\uff0c\u4ee5\u540e\u518d\u6539\u5427\u3002
\"\u7ec6\u5316\u7b97\u6cd5matlab<\/p>\n

Isrc = imread('pic\/0.bmp'<\/span>); if<\/span> ndims<\/span>(Isrc) == 3<\/span> I = rgb2gray(Isrc); else<\/span> I = Isrc; end<\/span> I = im2bw(I,0.5<\/span>); %\u5916\u56f4\u6269\u5c55\u8fb9\u754c<\/span> [H,W]<\/span> = size<\/span>(I); I = [zeros(2<\/span>,W);I;zeros(2<\/span>,W)]<\/span>; I = [zeros(H+4<\/span>,2<\/span>),I,zeros(H+4<\/span>,2<\/span>)]<\/span>; [H,W]<\/span> = size<\/span>(I); for<\/span> k = 1<\/span>:10<\/span> %\u8fed\u4ee3\u6b21\u6570<\/span> p = zeros<\/span>(8<\/span>,1<\/span>); NzI = zeros<\/span>(H,W); ZI = zeros<\/span>(H,W); P024I = zeros<\/span>(H,W); P246I = zeros<\/span>(H,W); I2 = I; for<\/span> i<\/span> = 2<\/span>:H-1<\/span> for<\/span> j<\/span> = 2<\/span>:W-1<\/span> if<\/span> I(i<\/span>,j<\/span>) p(1<\/span>) = I(i<\/span>,j<\/span>+1<\/span>); p(2<\/span>) = I(i<\/span>-1<\/span>,j<\/span>+1<\/span>); p(3<\/span>) = I(i<\/span>-1<\/span>,j<\/span>); p(4<\/span>) = I(i<\/span>-1<\/span>,j<\/span>-1<\/span>); p(5<\/span>) = I(i<\/span>,j<\/span>-1<\/span>); p(6<\/span>) = I(i<\/span>+1<\/span>,j<\/span>-1<\/span>); p(7<\/span>) = I(i<\/span>+1<\/span>,j<\/span>); p(8<\/span>) = I(i<\/span>+1<\/span>,j<\/span>+1<\/span>); NzI(i<\/span>,j<\/span>) = sum(p); ZI(i<\/span>,j<\/span>) = sum(abs<\/span>(diff(p)))+abs<\/span>(p(8<\/span>)-p(1<\/span>)); P024I(i<\/span>,j<\/span>) = p(1<\/span>) * p(3<\/span>) * p(5<\/span>); P246I(i<\/span>,j<\/span>) = p(3<\/span>) * p(5<\/span>) * p(7<\/span>); end<\/span> end<\/span> end<\/span> for<\/span> i<\/span> = 3<\/span>:H-1<\/span> for<\/span> j<\/span> = 3<\/span>:W-1<\/span> if<\/span> I(i<\/span>,j<\/span>) if<\/span> ((NzI(i<\/span>,j<\/span>) >= 2<\/span>) && (NzI(i<\/span>,j<\/span>) <= 6<\/span>)) && ... (ZI(i<\/span>,j<\/span>) == 2<\/span>) && ... ((P024I(i<\/span>,j<\/span>)==0<\/span>)||(ZI(i<\/span>,j<\/span>-1<\/span>)~=2<\/span>)) && ... ((P246I(i<\/span>,j<\/span>)==0<\/span>)||(ZI(i<\/span>-1<\/span>,j<\/span>)~=2<\/span>)) I2(i<\/span>,j<\/span>) = 0<\/span>; end<\/span> end<\/span> end<\/span> end<\/span> I = I2; end<\/span> figure(1<\/span>); subplot(121<\/span>); imshow(Isrc); subplot(122<\/span>); imshow(I2);<\/code><\/pre>\n

[1]: Lam, L., Seong-Whan Lee, and Ching Y. Suen, \u201cThinning Methodologies-A Comprehensive Survey,\u201d IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 14, No. 9, September 1992, page 879, bottom of first column through top of second column.
[2]\u5468\u51e4\u9999. \u5de5\u4e1a\u751f\u4ea7\u7ebf\u6807\u7b7e\u5b57\u7b26\u8bc6\u522b\u7cfb\u7edf\u7684\u8bbe\u8ba1\u4e0e\u5b9e\u73b0[D].\u7535\u5b50\u79d1\u6280\u5927\u5b66,2013.<\/p>\n","protected":false},"excerpt":{"rendered":"\u7ec6\u5316\u7b97\u6cd5matlab\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u7528matlab\u81ea\u5e26\u7684\u51fd\u6570\uff1aBW2=bwmorph(BW,'thin',n);n\u662f\u8981\u7ec6\u5316\u8fed\u4ee3\u7684\u6b21\u6570\uff0c\u4e5f\u53ef\u4ee5\u662fInf...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6702"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6702"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6702\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}