|
Image Processing : Working with Regions of Interest (ROIs) |
|
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. |
DEVICE, DECOMPOSED = 0, RETAIN = 2
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
CURSOR, xi, yi, /DEVICE
WDELETE, 0
ptTest = ROIout -> ContainsPoints(xi,yi)
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]
x = LINDGEN(7*7) MOD 7 + xi y = LINDGEN(7*7) / 7 + yi point = x + y * dims[0]
maxClr = !D.TABLE_SIZE - 1 TVLCT, 255, 255, 255, maxClr
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
OBJ_DESTROY, ROIout
The following figure displays a region covering South America and a point within the African continent. Your results will depend upon the ROI and point you have defined when running this program.
IDL Online Help (March 06, 2007)