Displaying ROI Objects in a Direct Graphics Window

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. Run the example procedure by entering drawroiex at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT drawroiex.pro.

  1. Prepare the display device and load a grayscale color table:
  2. DEVICE, DECOMPOSED = 0, RETAIN = 2 
    LOADCT, 0 
    
  3. Select and open the image file using the READ_DICOM function and get its size:
  4. kneeImg = READ_DICOM(FILEPATH('mr_knee.dcm', $ 
       SUBDIRECTORY = ['examples','data'])) 
    dims = SIZE(kneeImg, /DIMENSIONS) 
    
  5. Rotate the image 180 degrees so that the femur will be at the top of the display:
  6. kneeImg = ROTATE(BYTSCL(kneeImg), 2) 
    
  7. Open the file in the XROI utility to create an ROI containing the femur. The following line includes the ROI_GEOMETRY and STATISTICS keywords so that specific ROI information can be retained for printing in a later step:
  8. 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.

    Figure 6-3: Defining the Femur ROI

    imgroi03.jpg

  9. Create an ROI containing the tibia, using the following XROI statement:
  10. 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.

    Figure 6-4: Defining the Tibia ROI

    imgroi04.gif

  11. Create a Direct Graphics display containing the original image:
  12. WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1] 
    TVSCL, kneeImg 
    
  13. Load the 16-level color table to display the regions using different colors. Use DRAW_ROI statements to specify how each ROI is drawn:
  14. 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.

    Figure 6-5: Defined Region Objects Overlaid onto Original Image

    imgroi05.gif

  15. Print the statistics for the femur and tibia ROIs. This information has been stored in the femurGeom, femurStat, tibiaGeom and tibiaStat variable structures, defined in the previous XROI statements. Use the following lines to print geometrical and statistical data for each ROI:
  16. 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.

  17. Clean up object references that are not destroyed by the window manager when you close the Object Graphics displays:
  18. OBJ_DESTROY, [femurROIout, tibiaROIout]