|
Image Processing : Working with Regions of Interest (ROIs) |
|
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. |
DEVICE, DECOMPOSED = 0, RETAIN = 2 LOADCT, 5 TVLCT, R, G, B, /GET
file = FILEPATH('head.dat', SUBDIRECTORY =
['examples','data'])
img = READ_BINARY(file, DATA_DIMS = [80,100,57])
img = CONGRID(img, 200, 225, 57)
oROIGroup = OBJ_NEW('IDLgrROIGroup')
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.
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
oPoly = OBJ_NEW('IDLgrPolygon', verts, POLYGON = conn, $
COLOR = [128, 128, 128], SHADING = 1)
oModel -> Add, oPoly XOBJVIEW, oModel, /BLOCK
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.
![]() |
IDL Online Help (March 06, 2007)