Hellou. Could I ask for help finding the center of gravity of the object?

5 views (last 30 days)
I have a white object on a black background, so a binary image. The object is irregular and similar to a flattened cylinder. How can we find its center of gravity please?

Answers (1)

Walter Roberson
Walter Roberson on 10 May 2017
In the case where there are no disconnected pixels, then
info = regionprops( logical(YourImage), 'Centroid');
center_of_gravity = info.Centroid;
In the case where there might be disconnected pixels, then
info = regionprops( 0 + logical(YourImage), 'Centroid');
center_of_gravity = info.Centroid;
the "0 +" is there to turn the image into a label matrix instead of a binary image. If you pass in a binary matrix then normally the centroid of each disconnected region would be calculated.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!