THRESH_ADAP Function
Performs adaptive thresholding on an array.
Usage
result = THRESH_ADAP(image, wxdim[, wydim[, wzdim]])
Input Parameters
image—A 1D, 2D, or 3D array containing a signal; point or signal-interleaved signals; an image; image, row or pixel interleaved images; or a volume.
wxdim—The width of the threshold window. This value is wxdim  the width of image.
wydim—(optional) The height of the threshold window. This value is wydim  the height of image. (Required for images and volumes.)
wzdim—(optional) The depth of the threshold window. This value is wzdim  the depth of image. (Required when image is a volume.)
Returned Value
result—An array of data type byte, if binary thresholding is performed; otherwise, the array returned is the same data type as image.
Keywords
Binary—If set, binary thresholding is performed.
Intleave—A scalar string indicating the type of interleaving of 2D input signals and 3D image arrays. Valid strings and the corresponding interleaving methods are:
*'point'—The 2D input array arrangement is (px) for p  point-interleaved signals of length x.
*'signal'—The 2D input image array arrangement is (xp) for p  signal-interleaved signals of length x.
*'pixel'—The input array arrangement is (pxy) for p  pixel-interleaved images of x-by-y.
*'row'—The 3D image array arrangement is (xpy) for p  row-interleaved images of x-by-y.
*'image'—The 3D image array arrangement is (xyp) for p  image-interleaved images of x-by-y.
*'volume'—The input image array is treated as a single entity.
Lower_Tol—The lower tolerance used for the threshold comparison. Either Tolerance, or both Upper_Tol and Lower_Tol must be specified. (Default: Tolerance)
Set_False—The value that the result is set to when the comparison is false. (Default: 0)
 
note
The Set_False keyword is ignored if Binary = 0.
Set_True—The value that the result is set to when the comparison is true. (Default: 255)
Stat_Type—A scalar string indicating the statistical function to compute within the threshold window. Valid strings are: 'avg', 'min', 'max', 'median', 'stdev', or 'range'. (Default: 'avg')
Tolerance—The tolerance around the statistical calculation used for the threshold comparison. Either Tolerance, or both Upper_Tol and Lower_Tol must be specified.
Upper_Tol—The upper tolerance used for the threshold comparison. Either Tolerance, or both Upper_Tol and Lower_Tol must be specified. (Default: Tolerance)
Discussion
The purpose of image segmentation is to separate the image into regions possessing similar characteristics. General thresholding uses only the pixel amplitude as the segmentation characteristic. Some difficulties arise with using only the pixel amplitude for thresholding, such as: choosing an absolute pixel amplitude at which to threshold can be tough, and sometimes noise or other undesired artifacts are incorrectly grouped with the desired objects. Using the THRESH_ADAP function is one way around such difficulties.
Adaptive thresholding provides a method for rejecting local pixel values based on a tolerance around a statistical measure within a local image window. Adaptive thresholding also does not require an absolute pixel amplitude threshold value. Instead, the threshold value is constantly changed based on a local image statistical measure.
For all statistical measures (using the keyword Stat_Type) except the standard deviation, a pixel is set to Set_True if it is within ± the upper and lower tolerances, respectively, of the local statistical measure. For the standard deviation, a pixel is set to Set_True if it is within ± the upper and lower tolerances of the local mean ± the local standard deviation.
Example 1
image = IMAGE_READ(!IP_Data + 'xray.tif')
; Segment the image using adaptive thresholding based on the
; average value in a 5-by-5 window. The tolerance around the
; window average will be ± 1.5.
seg_image = THRESH_ADAP(image('pixels'), 5, 5, /Binary, $
Stat_Type = 'avg', Tolerance = 1.5)
; Display the binary segmented image.
TVSCL, seg_image
Example 2
image = IMAGE_READ(!IP_Data + 'objects.tif')
; Segment the objects using the standard deviation. The tolerance
; will be ± 2.0 of the window average ± the standard deviation.
seg_image = THRESH_ADAP(image('pixels'), 3, 3, /Binary, $
Stat_Type = 'stdev', Tolerance = 2.0)
; Display the binary segmented image.
TVSCL, seg_image
See Also