matlab关于图像质心的求解,为什么我最后标记不成功啊,求大神帮我看下程序错在哪了

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;
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');
subplot(224),imshow(I_bw);
hold on;
for k = 1:length(s)
c = s(k).Centroid;
plot(c(1),c(2), 'b*');
end

温馨提示:答案为网友推荐,仅供参考