Testing an ROI for Point Containment
The IDLanROI::ContainsPoints function method determines whether a point having given coordinates lies inside, outside, on the boundary of, or on the vertex of a designated ROI. The following example allows the creation of an ROI within an image of the world using XROI. After exiting XROI, a point is selected and tested to determine its relationship to the ROI. The example then creates textual and graphical displays of the results. Complete the following steps for a detailed description of the process.
Example Code
See containmenttest.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering containmenttest at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT containmenttest.pro.
- Prepare the display device:
- Select and open the image file and get its dimensions:
- Open the file in the XROI utility to create an ROI:
- Load the image color table and display the image in a new window:
- The CURSOR function allows you to select and define the coordinates of a point. After entering the following line, position your cursor anywhere in the image window and click the left mouse button to select a point:
- Delete the window after selecting the point:
- Using the coordinates returned by the CURSOR function, determine the placement of the point in relation to the ROI object using IDLanROI::ContainsPoints:
- The value of ptTest, returned by the previous statement, ranges from 0 to 3. Create the following vector of string data where the index value of the string element relates to value of ptTest. Print the actual and textual value of ptTest:
- Complete the following steps to create a visual display of the ROI and the point that you have defined. First, create a 7 by 7 ROI indicating the point:
- Define the color with which the ROI and point are drawn:
- Draw the point within the original image and display it:
- Draw the ROI over the image using DRAW_ROI:
- Clean up object references that are not destroyed by the window manager:
img = READ_PNG(FILEPATH('avhrr.png', $
SUBDIRECTORY = ['examples', 'data']), R, G, B)
dims = SIZE(img, /DIMENSIONS)
XROI, img, REGIONS_OUT = ROIout, R, G, B, /BLOCK, $ TITLE = 'Create ROI and Close Window'After creating any region using the tool of your choice, close the XROI utility to save the ROI object data in the variable, ROIout.
TVLCT, R, G, B WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = 'Left-Click Anywhere in Image' TV, img
containResults = [ $ 'Point lies outside ROI', $ 'Point lies inside ROI', $ 'Point lies on the edge of the ROI', $ 'Point lies on vertex of the ROI'] PRINT, 'Result =',ptTest,': ', containResults[ptTest]
regionPt = img regionPt[point] = maxClr WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1], $ TITLE='Containment Test Results' TV, regionPt
DRAW_ROI, ROIout, COLOR = maxClr, /LINE_FILL, $ THICK = 2, LINESTYLE = 0, ORIENTATION = 315, /DEVICE
