Center of mass in binary image
13 ビュー (過去 30 日間)
古いコメントを表示
Hello, I have a binary image with one object. How can I calculate the center of this object, to mark it in my image and to write the coordinates in the corner of this image, like this: object: X, Y
I used this code to calculate the center of mass:
s = regionprops(bw, 'centroid');
centroids = cat(1, s.Centroid);
imshow('MY_IMAGE.jpg')
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
hold off
but how can i plot this coordinates on my image in the left corner?
Thank you for help
0 件のコメント
採用された回答
David Sanchez
2013 年 9 月 18 日
use text command:
your_string = strcat( num2str(centroids(:,1)),'-', num2str(centroids(:,2)));
text(10,10,your_string)
change the position by changing the "10,10" values
5 件のコメント
Image Analyst
2013 年 9 月 18 日
Use sprintf to create your string, and cast your numbers to integers or use %.0f:
textString = sprintf('Object: %d, %d (coordinates)', int32(X), int32(Y));
text(x,y,textString);
その他の回答 (2 件)
Walter Roberson
2013 年 9 月 18 日
ndgrid() of 1:width and 1:height, do a logical indexing of those according to the binary image, calculate the mean() of what is left in each of the two coordinate matrices. Result will be centre of mass along each of the two coordinates.
0 件のコメント
Mauldy Putra
2016 年 12 月 16 日
i want to ask, in your code there is bw i want to know what is bw stand for? cause i try use your code it's said "Undefined function or variable 'bw'."
thank you
1 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!