Center of mass in binary image
Show older comments
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
Accepted Answer
More Answers (2)
Walter Roberson
on 18 Sep 2013
0 votes
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.
Mauldy Putra
on 16 Dec 2016
0 votes
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 Comment
Walter Roberson
on 16 Dec 2016
bw is the binary image whose center of mass is to be found.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!