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.

  1. Prepare the display device and load a grayscale color table:
  2. DEVICE, DECOMPOSED = 0, RETAIN = 2 
    LOADCT, 0 
    
  3. Select the file, read in the data and get the image dimensions:
  4. file = FILEPATH('md1107g8a.jpg', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    READ_JPEG, file, img, /GRAYSCALE 
    dims = SIZE(img, /DIMENSIONS) 
    
  5. Double the size of the image for display purposes and compute the new dimensions:
  6. img = REBIN(BYTSCL(img), dims[0]*2, dims[1]*2) 
    dims = 2*dims 
    
  7. Create a window and display the original image:
  8. 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.

    Figure 6-8: Original Image Showing Region to be Selected

    imgroi08.jpg

  9. 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:
  10. 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.

  11. Delete the window after selecting the point:
  12. WDELETE, 0 
    
  13. Set the topmost color table entry to red:
  14. topClr = !D.TABLE_SIZE - 1 
    TVLCT, 255, 0, 0, topClr 
    
  15. Display the initial region using the previously defined color:
  16. 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.

    Figure 6-9: Square ROI at Selected Coordinates

    imgroi09.gif

  17. Using the REGION_GROW function syntax,
  18. 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.

  19. Show the results of growing the original region using threshold values:
  20. 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.

  21. Expand the original region using a value of 7 for STDDEV_MULTIPLIER:
  22. stddevPixels = REGION_GROW(img, roiPixels, $ 
       STDDEV_MULTIPLIER = 7) 
    
  23. Create a new window and show the resulting ROI:
  24. 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).

Figure 6-10: Regions Expanded Using REGION_GROW

imgroi10ab.gif

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.