|
Image Processing : Working with Regions of Interest (ROIs) |
|
The REGION_GROW function is an analysis routine that allows you to identify a complicated region without having to manually draw intricate boundaries. This function expands a given region based upon the constraints imposed by either a threshold range (minimum and maximum pixel values) or by a multiplier of the standard deviation of the original region. REGION_GROW expands an original region to include all connected neighboring pixels that fall within the specified limits.
The following example interactively defines an initial region within a cross-section of a human skull. The initial region is then expanded using both methods of region expansion, thresholding and standard deviation multiplication. Complete the following steps for a detailed description of the process.
| Example Code See regiongrowex.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
file = FILEPATH('md1107g8a.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, img, /GRAYSCALE
dims = SIZE(img, /DIMENSIONS)
img = REBIN(BYTSCL(img), dims[0]*2, dims[1]*2) dims = 2*dims
WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = 'Click on Image to Select Point of ROI' TVSCL, img
The following figure shows the initial image.
![]() |
CURSOR, xi, yi, /DEVICE x = LINDGEN(10*10) MOD 10 + xi y = LINDGEN(10*10) / 10 + yi roiPixels = x + y * dims[0]
| Note A region can also be defined and grown using the XROI utility. See the XROI procedure in the IDL Reference Guide for more information. |
WDELETE, 0
topClr = !D.TABLE_SIZE - 1 TVLCT, 255, 0, 0, topClr
regionPts = BYTSCL(img, TOP = (topClr - 1)) regionPts[roiPixels] = topClr WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = 'Original Region' TV, regionPts
The following figure shows the initial ROI that will be input and expanded with the REGION_GROW function.
Result = REGION_GROW(Array, ROIPixels [, /ALL_NEIGHBORS] [, STDDEV_MULTIPLIER=value | THRESHOLD=[min,max]] )
input the original region, roipixels, and expand the region to include all connected pixels which fall within the specified THRESHOLD range:
newROIPixels = REGION_GROW(img, roiPixels, $ THRESHOLD = [215,255])
| Note If neither the THRESHOLD nor the STDDEV_MULTIPLIER keywords are specified, REGION_GROW automatically applies THRESHOLD, using the minimum and maximum pixels values occurring within the original region. |
regionImg = BYTSCL(img, TOP = (topClr-1)) regionImg[newROIPixels] = topClr WINDOW, 2, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = 'THRESHOLD Grown Region' TV, regionImg
| Note An error message such as Attempt to subscript REGIONIMG with NEWROIPIXELS is out of range indicates that the pixel values within the defined region fall outside of the minimum and maximum THRESHOLD values. Either define a region containing pixel values that occur within the threshold range or alter the minimum and maximum values. |
The left-hand image in the following figure shows that the region has been expanded to clearly identify the optic nerves. Now expand the original region by specifying a standard deviation multiplier value as described in the following step.
stddevPixels = REGION_GROW(img, roiPixels, $ STDDEV_MULTIPLIER = 7)
WINDOW, 3, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = "STDDEV_MULTIPLIER Grown Region" regionImg2 = BYTSCL(img, TOP = (topClr - 1)) regionImg2[stddevPixels] = topClr TV, regionImg2
The following figure displays the results of growing the original region using thresholding (left) and standard deviation multiplication (right).
| Note Your results for the right-hand image may differ. Results of growing a region using a standard deviation multiplier will vary according to the exact mean and deviation of the pixel values within the original region. |
IDL Online Help (March 06, 2007)