ImageGenerateROIMask / FindPointsInPoly

If I use ImageGenerateROIMask and FindPointsInPoly to test whether image pixels lie within a polyhedron defined by a pair of x, y coordinate waves, should I get the same results? If so, I have a bug to find.

 

I haven't used either of these functions. But from looking at the working principles of both, I assume you have at least a few translation steps involved to get the output you are trying to compare. Do you have a simple demo example at hand?

Hi Tony,

This is the type of problem that you should send to support@wavemetrics.com with an experiment that illustrates the issue.  In general, ImageGenerateROIMask works in pixels with limited resolution.  Also, you may want to take a look at PolygonOp that has some options to control accuracy relating to resolution.

AG

I have only used FindPointsInPoly and find it very fast and reasonably precise. The help file mentioned that it has limited precision and I can confirm that based on my experience (flow cytometry data using polygon gating) as I have found points counted as in the Poly while it is clearly outside when graphed, vice versa. These points are very close to the polygon line and does not affect our overall analysis conclusions. I have not used ImageGenerateROIMask nor PolygonOp. 

I found the Winding number algorithm to be more precise (https://www.engr.colostate.edu/~dga/documents/papers/point_in_polygon.p…). However, a function based on this method is 50x slower than the builtin FindPointsInPoly based on the datasets I worked with (50-100k points, Apple M1 Pro cpu). The precision benefit versus processing time is something to be weighted based on your application and workstation performance. 

The function can be optimized. I wrote a more efficient winding number function that take advantage of Multithread wave handling. It is still slower than the builtin FindPointsInPoly but much more tolerable. However, I have to be honest this function is not very human readable.

The Raycasting is another algorithm that works (https://www.codeproject.com/Tips/626992/Check-if-a-Point-is-Inside-the-…). I found it to be somewhere in the middle. In my dataset it is about 20x slower than the builtin FindPointsInPoly and a little less precise than Winding. I did not try to optimize the Raycasting method.