Ask Your Question

Will this code give me the coordinates for the intensity-weighted centroid of image?

asked 2016-08-18 03:43:01 -0500

Mattis gravatar image

updated 2016-08-18 04:34:23 -0500

image description

Mat image;
Moments moments(image);
int x = moments.M10 / moments.M00;
int y = moments.M01 / moments.M00;
edit retag flag offensive close merge delete


yes. (well, maybe. unsure, if i understand you)

(what did you want ? there's the geometric center (cen of bbox), and the center-of-mass, which you got here)

berak gravatar imageberak ( 2016-08-18 04:07:17 -0500 )edit

I need to find the center of an irregular shape with the highest intensity offset from the geometric center. The intensity level should be considered when calculating the center.

Mattis gravatar imageMattis ( 2016-08-18 04:14:13 -0500 )edit

moments() should be appplied to binary images, so the intensity is the same for all .

please explain: "highest intensity offset from the geometric center."

berak gravatar imageberak ( 2016-08-18 04:18:15 -0500 )edit

I have included an example image.

Mattis gravatar imageMattis ( 2016-08-18 04:35:38 -0500 )edit

cv::moments has a boolean input argument isBinaryImage. So I guess it is prepared to receive non-binary images. I don't really know what is the result, I guess you should try it, plot the resulting x,y point and verify if the result makes sense.

Pedro Batista gravatar imagePedro Batista ( 2016-08-18 08:31:40 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-18 17:49:03 -0500

Tetragramm gravatar image

updated 2016-08-18 17:51:51 -0500

It will do that yes. Note that it doesn't work on multi-channel images, so you need to either convert to grayscale, or something else to reduce your example to a single channel. Perhaps extract just the red, in your case.

But yes, you do get the intensity weighted centroid if you pass binaryImage = false.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-08-18 03:43:01 -0500

Seen: 872 times

Last updated: Aug 18 '16