logo资料库

多个连通域的识别以及质心标记代码.docx

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
h=imread('C:\Users\Administrator\Desktop\角点.png'); f=im2bw(h); g=1-f; se=strel('disk',1); fo=imopen(g,se); I_bw =imclose(fo,se); imshow(I_bw) [L,num]=bwlabel(I_bw,8); plot_x=zeros(1,num);%%用于记录质心位置的坐标 plot_y=zeros(1,num); for k=1:num %%num 个区域依次统计质心位置 sum_x=0;sum_y=0;area=0; [height,width]=size(I_bw); for i=1:height for j=1:width if L(i,j)==k sum_x=sum_x+i; sum_y=sum_y+j; area=area+1; end end end plot_x(k)=fix(sum_x/area); plot_y(k)=fix(sum_y/area); end for i=1:num hold on
plot(plot_y(i) ,plot_x(i), '*') end
分享到:
收藏