centroid of convex hull

hi, i want to find de centroid of convex hull, how i can do it in matlab? I formed the convex hull with n-dimensional points. To find the convex hull i use convhull and convhulln thanks for your help

 Accepted Answer

You need to get a binary image first. If you just have x,y coordinates, like you used convhull, then you need to call poly2mask(). If you have an image of non-convex objects, then you need to call bwconvhull() and it will give you an image of all objects' convex hulls. Then simply call regionprops asking for the centroid.
measurements = regionprops(binaryImage, 'Centroid');
It's a structure array. Each element of measurements is a structure with fields that represent the measurements you asked it to make, like Centroid, area, whatever.

13 Comments

thanks, but if i have convex hull formed with point in 3d, 4d. etc, i can use poly2mask() and regionprops ?
I don't know what 3d, 4d, etc. means. What is "d"? Dimensions? Do you mean a 3, 4, 5, or more dimensional matrix? Do you have a binary image you'd like to upload to help explain your situation?
My guess is that the OP is not doing image processing at all, but is calculating a convex hull from an N-d point cloud. I think the OP wants to do something like this:
Pts = .... %MxN matrix of points, where N is the number of dimensions
CH = convhulln(Pts);
M = mean( Pts(CH,:)); %this should be the mean of the convex hull
The centroid of the subset of the points that comprise the convex hull is not the centroid of the solid convex hull. Just think a little bit and you can think of plenty of cases, if not most cases, where it's not true. For example a "J" shape. Lots of CH points along the bottom curve but only 1 at the top tip of the J. In fact it's harder to think of a case where that could be true.
Ah yes, I was misunderstanding the question. Indeed you are correct-- the centroid of the solid convex hull will indeed be quite different, and is quite complicated to calculate for 3d--you basically would have to integrate over the volume, a rather difficult chore.
Difficultish but doable.
ok, I see it's somewhat complicated, thanks
If I get some time I'll see what I can do. There might be a simplified method for this because the object will be convex.
Matt J might have some interesting ideas to add.
I still don't see any reason why regionprops() couldn't do it. You could ask Steve or Jeff but I think it can, at least I don't see any reason off the top of my head to discard it yet.
Judging that the author is the same as that of vert2con() I would be inclined to trust it.
After some testing of course.
Matt J
Matt J on 31 Jan 2013
Edited: Matt J on 31 Jan 2013
I would give it the benefit of the doubt, but since you brought it up, vert2con and con2vert are not without their bugs. Unfortunately, he no longer actively monitors feedback and hasn't replied to my bug reports, so I've had to make a number of my own fixes to them as the basis for my versions
thanks for your help, i'm going to try your ideas.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!