center of mass of binary image
Show older comments
hi , i want to know how to calculate center of mass of the binary image(silhouette).below is the image where i have crop the image basedon it boundary box
Accepted Answer
More Answers (2)
gwoo
on 21 Mar 2019
This is the fastest simpliest way I've seen to do it without regionprops:
[r, c] = find(binaryImage == 1);
rowcolCoordinates = [mean(r), mean(c)];
You haven't attached any image.
If your image is a single connected blob, regionprops can give you the centre of mass with the centroid property.
If you want the centre of mass for the whole image, regardless of how many blobs are in it, it's fairly trivial:
[x, y] = meshgrid(1:size(img, 2), 1:size(img, 1));
weightedx = x .* img;
weightedy = y .* img;
xcentre = sum(weightedx(:)) / sum(img(:));
ycentre = sum(weightedy(:)) / sum(img(:));
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!

