How to find Center of Mass for my entire binary image?

idow09 picture idow09 · Mar 24, 2014 · Viewed 12.3k times · Source

I'm interested in finding the coordinates (X,Y) for my whole, entire binary image, and not the CoM for each component seperatly. How can I make it efficiently? I guess using regionprops, but couldn't find the correct way to do so.

Answer

Shai picture Shai · Mar 24, 2014

You can define all regions as a single region for regionprops

props = regionprops( double( BW ), 'Centroid' ); 

According to the data type of BW regionprops decides whether it should label each connected component as a different region or treat all non-zeros as a single region with several components.


Alternatively, you can compute the centroid by yourself

[y x] = find( BW );
cent = [mean(x) mean(y)];