Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Find whether a point is inside or outside a ROI or Region

Hi all,
 
I need to find whether a point is lies inside an ROI. Is there any direct or indirect VI doing this? My ROI is huge list of points (Say a polygon ROI with more than 10,000 points on the contour).
 
We can use the Ray tracing algorithm, shooting a line and find howmany times it hits the contour. But the number of points is huge, so it may be time consuming. I also have a list of points to be found whether it is inside or not. So if any of you know some simple algorithm or VI please let me know.
 
Thanks,
senthil kumar m
0 Kudos
Message 1 of 10
(10,856 Views)
A simple way of doing this is to create a mask using the ROItoMask VI and then plug the point you want to check into GetPixelValue to see whether it is lit up or not.
 
Ken Pietrzak
Dragonfly Computing
Message 2 of 10
(10,846 Views)
If you could characterize your ROI a bit more (is it convex, does it contain holes, is it non self intersecting, does it roughly fit some geometric shape, etc.) I may be able to come up with something more clever. As it stands, the simplist thing to do would probably be to call IMAQ ROIToMask, and then check if the point in the resulting mask image is 0 or not using IMAQ GetPixelValue.

Give that a try and see if the performance is adequate for your needs.

Kevin C.
National Instruments
NI Vision
Message 3 of 10
(10,846 Views)

Hi Ken & Kevin,

I appreciate your suggestions. Yes, thats the simplest way to do. I will do that.

One problem could be my image size is very big - say 8000 * 23000 resolution. So it might putup lot of memory issues. Anyway thanks for the soution dudes. If you have anything more please let me know.

My image has irregular shapes, its not always complex. It has intersecting of shapes like two circles merged.

Thanks,

senthil kumar m

0 Kudos
Message 4 of 10
(10,831 Views)
Hai Logic,
 
        Try these steps:
 
        Instead of getting the extracting the entire ROI,
 
        Find out the ROI points which are nearer to your point. Points which say are less than some 100 pixel or the first 20 nearest points just by mathematical calculation. Now construct the ROI with these points(of course a maximum of one side would be left out). Extract this portion alone and see whether the point lies in it. Just check if this works.
 
Thanks,
Vasanth.
Ya Ya
0 Kudos
Message 5 of 10
(10,777 Views)
Hi  ....
 
I am new to this forum and I am new to image processing /matlab also.
 
 
I also have a similar question like in this thread..can anyone help me with  to find whether a point is lies inside an ROI.  My ROI is a non convex.
 
 I  have a list of points to be found whether it is inside or not. So if any of you know some way to do this pls let me know.
 
Thanks,
0 Kudos
Message 6 of 10
(10,571 Views)
Hello 4342,
 
If you are looking to do this processing in LabVIEW, it appears this forum should answer your question.  If you have a different issue, please repost with a more detailed description.
 
However, if you are inquiring as to how to do this processing in MATLAB, I would suggest posting on a MathWorks forum.
 
 
Regards,
Jasper S
0 Kudos
Message 7 of 10
(10,551 Views)
You can always first compare your point to the global rectangle of the ROI to eliminate the need to process every point extensively.
Randall Pursley
0 Kudos
Message 8 of 10
(10,534 Views)
To determine if a point is within a curve, the easiest way is to calculate its winding number.  This involves a lot of calculations using complex numbers, but it can be reduced to the following steps:
 
Store the contour points in an array, and store a duplicate of the first point as the last point.
 
Subtract the point A from each point in your contour to get vectors.
 
Use Atan2(y,x) to determine the angle for each vector in the contour.
 
Use Unwrap Phase to eliminate jumps in the angle.
 
Compare the first angle to the last angle in the contour.  If they are equal, the point is outside the curve.  If they differ by a multiple of 2 Pi, the point is inside the curve.
 
If the point is on the curve, the angle may or may not jump at the end.  To identify a point that is on the curve, search the list of unwrapped angles for a difference of exactly Pi (or -Pi).  If this exists, the point is on the curve.
 
The algorithm will not work if point A is equal to a point on the contour, so it would probably be a good idea to search to make sure none of the contour points are equal to the point A, also.
 
I attached an example that demonstrates this concept.
 
Bruce
 
Bruce Ammons
Ammons Engineering
Message 9 of 10
(10,284 Views)

As my contribution to this 5-old thread, since I didn't find any better solution than doing it myself, a VI which tests if a point is inside any of the [multiple] ROIs of an image. Implementation is for type 2 (rectangle), 4 (ellipse), 5 (closed polygon) and 6 (closed freehand). For types 2,5,6, the technique of the preceding post is used. Further types (rotated rectangle, annulus) could be done but it would be tedious. Provided for LV10.

Message 10 of 10
(7,909 Views)