MATLAB Answers

how to calculate the centroid of image ?

18 views (last 30 days)
ElizabethR on 29 Apr 2016
Commented: Walter Roberson on 3 May 2016
i have a binary image with size is 11 x 11 pixel. And i calculate the centroids of the image using centroid function in regionprops. The centroid result is 5,6897 and 6,0690. Why the entroid result is not 6 and 6 ? if i think, the centroids of 11 x 11 pixel is 6 and 6 , is that right ? thanks


Sven on 29 Apr 2016
IM = true(11,11)
ans =
Area: 121
Centroid: [6 6]
BoundingBox: [0.5000 0.5000 11 11]
So the centroid of an 11-by-11 image with all pixels on is [6,6]. If you're getting a centroid of [5.6897,6.0690], then your image isn't an 11-by-11 with all pixels on.
Sven on 3 May 2016
Hi Eliz, you will need to include code in order to allow people to help you on this question. You'll notice that my comment's code matches the description of the problem that you have given, but doesn't match the output you are describing.
So I suspect that your image doesn't have all pixels set to ON. Maybe a few pixels here and there are OFF, and that's why the centroid doesn't match [6,6]. If you can show us code that produces your actual output then we can help.
By the way, also consider checking back through your old posts and accept answers that have answered your questions - it helps us know which ones you still want help on.
Walter Roberson
Walter Roberson on 3 May 2016
Which MATLAB version are you using?

Sign in to comment.

Answers (0)


Community Treasure Hunt

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

Start Hunting!