|
Image Processing : Working with Regions of Interest (ROIs) |
|
The DRAW_ROI procedure displays single or multiple IDLanROI objects in a Direct Graphics window. The procedure allows you to layer the ROIs over the original image and specify the line style and color with which each region is drawn. The DRAW_ROI procedure also provides a means of easily displaying interior regions or "holes" within a defined ROI.
The following example uses the XROI utility to define two regions, a femur and tibia from a DICOM image of a knee, and draws them in a Direct Graphics window. Complete the following steps for a detailed description of the process.
| Example Code See drawroiex.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
DEVICE, DECOMPOSED = 0, RETAIN = 2 LOADCT, 0
kneeImg = READ_DICOM(FILEPATH('mr_knee.dcm', $
SUBDIRECTORY = ['examples','data']))
dims = SIZE(kneeImg, /DIMENSIONS)
kneeImg = ROTATE(BYTSCL(kneeImg), 2)
XROI, kneeImg, REGIONS_OUT = femurROIout, $ ROI_GEOMETRY = femurGeom,$ STATISTICS = femurStats, /BLOCK
Select the Draw Polygon button from the XROI utility toolbar, shown in the following figure. Position the crosshairs anywhere along the border of the femur and click the left mouse button to begin defining the ROI. Move your mouse to another point along the border and left-click again. Repeat the process until you have defined the outline for the ROI. To close the region, double-click the left mouse button. Your display should appear similar to the following figure. Close the XROI utility to store the ROI information in the variable, femurROIout.
XROI, kneeImg, REGIONS_OUT = tibiaROIout, $ ROI_GEOMETRY = tibiaGeom, $ STATISTICS = tibiaStats, /BLOCK
Select the Draw Polygon button from the XROI utility toolbar. Position the crosshairs symbol anywhere along the border of the tibia and draw the region shown in the following figure, repeating the same steps as those used to define the femur ROI. Close the XROI utility to store the ROI information in the specified variables.
WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1] TVSCL, kneeImg
LOADCT, 12 DRAW_ROI, femurROIout, /LINE_FILL, COLOR = 80, $ SPACING = 0.1, ORIENTATION = 315, /DEVICE DRAW_ROI, tibiaROIout, /LINE_FILL, COLOR = 42, $ SPACING = 0.1, ORIENTATION = 30, /DEVICE
In the previous statements, the ORIENTATION keyword specifies the degree of rotation of the lines used to fill the drawn regions. The DEVICE keyword indicates that the vertices of the regions are defined in terms of the device coordinate system where the origin (0,0) is in the lower-left corner of the display.
Your results should appear similar to the following figure, with the ROI objects layered over the original image.
![]() |
PRINT, 'FEMUR Region Geometry and Statistics' PRINT, 'area =', femurGeom.area, $ 'perimeter = ', femurGeom.perimeter, $ 'population =', femurStats.count PRINT, ' ' PRINT, 'TIBIA Region Geometry and Statistics' PRINT, 'area =', tibiaGeom.area, $ 'perimeter = ', tibiaGeom.perimeter, $ 'population =', tibiaStats.count
| Note Notice the difference between the "area" value, indicating the region's geometric area, and the "population" value, indicating the number of pixels covered by the region when it is displayed. This difference is expected and is explained in the section, Contrasting an ROI's Geometric Area and Mask Area. |
OBJ_DESTROY, [femurROIout, tibiaROIout]
IDL Online Help (March 06, 2007)