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.
- Prepare the display device and load a color table to more easily distinguish image features:
- Select and open the file:
- Resize the array for display purposes and to compensate for the sampling rate of the scan slices:
- Initialize an IDLanROIGroup object to which individual ROIs will be added:
- Use a FOR loop to define an ROI within every fifth slice of data. Add each ROI to the group:
- Compute the mesh for the ROI group using IDLanROIGroup::ComputeMesh:
- Prepare to display the mesh, scaling and translating the array for display in XOBJVIEW:
- Create an IDLgrPolygon object using the results of ComputeMesh:
- Add the polygon to the model and display the polygon object in XOBJVIEW:
- Clean up object references that are not destroyed by the window manager when you close the Object Graphics displays:
file = FILEPATH('head.dat', SUBDIRECTORY =
['examples','data'])
img = READ_BINARY(file, DATA_DIMS = [80,100,57])
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 & $ ENDFORNote
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 inGroupROIMesh.proin theexamples/doc/imagesubdirectory of the IDL installation directory.The following image shows samples of the ROIs to be defined.
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.
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.
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

