Creating a Surface Mesh of an ROI Group

An IDLanROIGroup contains multiple ROIs. The ROI group consists of either several ROIs defined in a single image, or a stack of ROIs, each of which has been defined from a separate slice of a multi-image data set. An ROI group can be translated into a surface mesh, a mask, or tested for point containment. The following example defines ROIs from a data set containing 57 MRI images of a human head. After all ROIs have been defined with the utility and each region has been added to the group, IDLanROI::ComputeMesh triangulates a surface mesh. The resulting vertices and connectivity array are used to create a polygon object that is displayed using XOBJVIEW. Complete the following steps for a detailed description of the process.

Example Code
See grouproimesh.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering grouproimesh at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT grouproimesh.pro.

  1. Prepare the display device and load a color table to more easily distinguish image features:
  2. DEVICE, DECOMPOSED = 0, RETAIN = 2 
    LOADCT, 5 
    TVLCT, R, G, B, /GET 
    
  3. Select and open the file:
  4. file = FILEPATH('head.dat', SUBDIRECTORY = 
    ['examples','data']) 
    img = READ_BINARY(file, DATA_DIMS = [80,100,57]) 
    
  5. Resize the array for display purposes and to compensate for the sampling rate of the scan slices:
  6. img = CONGRID(img, 200, 225, 57) 
    
  7. Initialize an IDLanROIGroup object to which individual ROIs will be added:
  8. oROIGroup = OBJ_NEW('IDLgrROIGroup') 
    
  9. Use a FOR loop to define an ROI within every fifth slice of data. Add each ROI to the group:
  10. FOR i=0, 54, 5  DO BEGIN & $ 
       XROI, img[*, *,i], R, G, B, REGIONS_OUT = oROI, $ 
          /BLOCK, ROI_SELECT_COLOR = [255, 255, 255] & $ 
       oROI -> GetProperty, DATA = roiData & $ 
       roiData[2, *] = 2.2*i & $ 
       oRoi -> ReplaceData, roiData & $ 
       oRoiGroup -> Add, oRoi & $ 
    ENDFOR 
     

    Note
    The & after BEGIN and the $ allow you to use the FOR/DO loop at the IDL command line. These & and $ symbols are not required when the FOR/DO loop in placed in an IDL program as shown in GroupROIMesh.pro in the examples/doc/image subdirectory of the IDL installation directory.

    The following image shows samples of the ROIs to be defined.

    Figure 6-14: ROIs to be Defined

    imgroi14.gif

    To limit the time needed complete this exercise, the previous FOR statement arranges to display every fifth slice of data for ROI selection. To obtain higher quality results, consider selecting an ROI in every other slice of data.

  11. Compute the mesh for the ROI group using IDLanROIGroup::ComputeMesh:
  12. result = oROIGroup -> ComputeMesh(verts, conn) 
     

    Note
    The ComputeMesh function will fail if the ROIs contain interior regions (holes), are self-intersecting or are of a TYPE other than the default, closed polygon.

  13. Prepare to display the mesh, scaling and translating the array for display in XOBJVIEW:
  14. nImg = 57 
    xymax = 200.0 
    zmax = float(nImg) 
    oModel = OBJ_NEW('IDLgrModel') 
    oModel -> Scale, 1./xymax,1./xymax, 1.0/zmax 
    oModel -> Translate, -0.5, -0.5, -0.5 
    oModel -> Rotate, [1,0,0], -90 
    oModel -> Rotate, [0, 1, 0], 30 
    oModel -> Rotate, [1,0,0], 30 
    
  15. Create an IDLgrPolygon object using the results of ComputeMesh:
  16. oPoly = OBJ_NEW('IDLgrPolygon', verts, POLYGON = conn, $ 
       COLOR = [128, 128, 128], SHADING = 1) 
    
  17. Add the polygon to the model and display the polygon object in XOBJVIEW:
  18. oModel -> Add, oPoly 
    XOBJVIEW, oModel, /BLOCK 
    
  19. Clean up object references that are not destroyed by the window manager when you close the Object Graphics displays:
  20. OBJ_DESTROY, [oROI, oROIGroup, oPoly, oModel] 
     

    The following figure displays the mesh created by defining an ROI in every other slice of data instead of from every fifth slice as described in this example. Therefore, your results will likely vary.

    Figure 6-15: Result of Creating a Mesh from a Group of ROIs

    imgroi15.jpg