close all;
I=imread('coins.png');
subplot(221);imshow(I);
title('原图');
level=graythresh(I);
bw=im2bw(I,level);
subplot(222);imshow(bw);
title('二值图');
I_bw=imfill(bw,'holes');
subplot(223);imshow(I_bw);
title('填充图');
s=regionprops(I_bw,'centroid');
centroids=cat(1,'s.centroid');
imtool(I)
hold (imgca,'on');
plot(imgca,centroids(:,1),centroids(:,2),'b*')
hold (imgca,'off');
最后一段改成如下:
close all;