Growing a Region
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. Run the example procedure by entering regiongrowex at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT regiongrowex.pro.
- Prepare the display device and load a grayscale color table:
- Select the file, read in the data and get the image dimensions:
- Double the size of the image for display purposes and compute the new dimensions:
- Create a window and display the original image:
- Define the original region pixels. Using the CURSOR function, select the original region by positioning your cursor over the image and clicking on the region indicated in the previous figure by the "+" symbol. Then create a 10 by 10 square ROI, named roipixels, at the selected x, y, coordinates:
- Delete the window after selecting the point:
- Set the topmost color table entry to red:
- Display the initial region using the previously defined color:
- Using the REGION_GROW function syntax,
- Show the results of growing the original region using threshold values:
- Expand the original region using a value of 7 for STDDEV_MULTIPLIER:
- Create a new window and show the resulting ROI:
file = FILEPATH('md1107g8a.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, img, /GRAYSCALE
dims = SIZE(img, /DIMENSIONS)
WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = 'Click on Image to Select Point of ROI' TVSCL, imgThe 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.
regionPts = BYTSCL(img, TOP = (topClr - 1)) regionPts[roiPixels] = topClr WINDOW, 0, XSIZE = dims[0], YSIZE = dims[1], $ TITLE = 'Original Region' TV, regionPtsThe 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, regionImgNote
An error message such asAttempt to subscript REGIONIMG with NEWROIPIXELS is out of rangeindicates 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.
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.


