views:

58

answers:

3

Does MATLAB have a built-in function to find general properties like center of mass & moments of inertia for a polygon defined as a list of (non-integer valued) points?

regionprops performs this task for integer valued points, on the assumption that these represent indices of pixels in an image. But the only functions I can find that treat non integral point lists are polyarea and inpolygon.

My kludge for now is to create a bwconncomp structure with all the points multiplied by some large value (like 10,000), then feeding it in to regionprops, but wondered if there is a more elegant solution.

A: 

One possibility is to farm out the calculations to the Java Topology Suite. I don't know about "moments of inertia", but it does at least have a centroid method.

kwatford
+1  A: 

I don't know of a function in MATLAB that would do this for you.

However, poly2mask might be of use for you to create the pixel masks to feed into regionprops. I also suggest that, should you decide to go this route, you carefully test how much the discretization affects the results, so that you don't create crazy large arrays (and waste time) for no real gain in accuracy.

Jonas
My thought was that multiplying by a large number wouldn't affect timing, because the number of points being processed wouldn't change. (this is true for code like the polygeom, as suggested by gnovice). However, I found out that bwconncomp returns an index to every pixel on the boundary, not just the vertices, so the number of pixels does scale with the multiplicative factor. So instead of multiplying by 10,000, I just divided by the smallest non-zero step in the vertex list, which is in general a bad solution, but due to the way these polygons were created, OK for me.
Marc
+1  A: 

You should check out the submission POLYGEOM by H.J. Sommer on the MathWorks File Exchange. It looks like it has all the property measurements you want, and nice documentation describing the formulae used in the code.

gnovice
Looks reasonable. The clever trick he does is to convert integrals over the surface to contour integrals. I like it.
Marc

related questions