www.gusucode.com > 《matlab图像处理与界面编程宝典》秦襄培 编著,每章的MATLAB源代码程序 > 第24章/代码24-6.txt

    
bw = imread('circles.png');                        % 读入图像
L=bwlabel(bw);                                     % 图像标记
s=regionprops(L, 'centroid');                      % 求区域属性   
a=regionprops(L, 'area')                           % 求区域属性
centroids = cat(1, s.Centroid);                    
imshow(bw)                                         % 显示原始图像 
hold on                                            % 继续绘图
plot(centroids(:,1), centroids(:,2), 'b*')         % 质心标识,蓝色星号
hold off                                           % 停止继续绘图