[英]How to get centriod coordinates of multiple points in binary image_matlab
只需使用regionprops
:
stats = regionprops(B,'Centroid')
以下是如何使用它的詳細方法:
首先,我將生成一些隨機點
a=zeros(50);
a(ind2sub(size(a),randi(numel(a),7,1)))=1;
a=padarray(a,[10 10]);
a=conv2(a,fspecial('gaussian',7,1),'same');
b=a>0.02;
imagesc(b);
然后使用regionprops:
stats = regionprops(b,'Centroid');
這只是繪制各種質心:
hold on;
for n=1:numel(stats)
plot(stats(n).Centroid(1),stats(n).Centroid(2),'rx'); hold on
text(stats(n).Centroid(1)-4,stats(n).Centroid(2)-4,...
['x=' num2str(stats(n).Centroid(1)) ', y=' num2str(stats(n).Centroid(2))],'Color','w' );
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.