Skip to main content

ImageThreshold

ImageThreshold [flags] imageMatrix

Performs thresholding operation converts a grayscale imageMatrix into a binary image. This operation supports all data types. However, the source wave must be a 2D matrix. If imageMatrix contains NaNs, the pixels corresponding to NaN values are mapped into the value 64. The values for the On and Off pixels are 255 and 0 respectively. The resulting image is stored in the wave M_ImageThresh.

Flags

/CCalculate the correlation coefficient between the original image and the image generated by the threshold operation. The correlation value is printed to the history area (unless the /Q flag is specified), it is also stored in the variable V_correlation.
/DEST=destWave
Specifies the destination wave created by the operation. If you do not use this flag, the operation saves the output in the wave M_ImageThresh in the current datafolder.
It is an error to specify the same wave as both srcWave and destWave.
When used in a function, ImageThreshold creates a real wave reference for the destination wave. See Automatic Creation of Wave References for details.
/DEST flag was added in Igor Pro 10.00.
/FREECreates the destination wave destWave as a free wave.
/FREE is allowed only in functions and only if destWave is a simple name or wave reference structure field.
See Free Waves for more discussion.
The /FREE flag was added in Igor Pro 10.00.
/Iuse this flag to invert the values written to the image, i.e., set to zero all pixels above threshold.
/M= methodThe calculated value will be printed to the history area (unless /Q is specified) and stored in the variable V_threshold.
method =0:Default. In this case you must use the /T flag to specify a manually-selected threshold.
method =1:Automatically calculate a threshold value using an iterative method.
method =2:Image histogram is a simple bimodal distribution.
method =3:Adaptive thresholding. Evaluates threshold based on the last 8 pixels in each row, using alternating rows.
The output wave M_ImageThresh has the same numeric type as the input wave. In particular, when the input numeric type is signed byte, the on and off pixel values are 127 and 0 respectively.
Note that this method is not supported when used as part of the operation ImageEdgeDetection.
method =4:Fuzzy thresholding using entropy as the measure for "fuzziness".
method =5:Fuzzy thresholding using a method that minimizes a "fuzziness" measure involving the mean gray level in the object and background.
method =6:Determines an ideal threshold by histograming the data and representing the image as a set of clusters that is iteratively reduced until there are two clusters left. The threshold value is then set to the highest level of the lower cluster. This method is based on a paper by A.Z. Arifin and A. Asano (see reference below) but modified for handling images with relatively flat histograms.
If the image histogram results in less than two clusters, it is impossible to determine a threshold using this method and the threshold value is set to NaN.
Added in Igor Pro 7.00.
method =7:Determines the ideal threshold value by maximizing the total variance between the "object" and "background". See <http://en.wikipedia.org/wiki/Otsu%27s_method>
Added in Igor Pro 7.00.
/NSets the background level to 64 (i.e., NaN)
/OOverwrite the original image with the calculated threshold image.
If you do not specify the /O flag, the threshold image is written into the wave M_ImageThresh.
/P= layerWhen imageMatrix is a 3D wave /P selects a specific layer for which to compute the threshold. layer is the zero-based layer index.
If layer is -1, which is the default value, the threshold is computed for all layers of imageMatrix .
The /P flag is not compatible with /O.
The /P flag was added in Igor Pro 7.00.
/QSuppress printing calculated correlation coefficients (/C) and calculated thresholds (/M) to the history area.
/R=roiSpecUse this flag to specify a region of interest (ROI). The ROI is defined by a wave of type unsigned byte (/b/u). The ROI wave must have the same number of rows and columns as the image wave. The ROI itself is defined by the entries/pixels whose values are 0. Pixels outside the ROI can take any nonzero value. The ROI does not have to be contiguous and can take any arbitrary shape. See ImageGenerateROIMask for more information on creating ROI waves.
In general, the roiSpec has the form {roiWaveName , roiFlag }, where roiFlag can take the following values:
0:Set pixels outside the ROI to 0
1:Set pixels outside the ROI as in original image
2:Set pixels outside the ROI to NaN (=64)
By default roiFlag is set to 1 and it is then possible to use the /R flag using the abbreviated form /R=roiWave .
/T=threshUse this flag when you know the desired threshold value.
/W=TwaveUse this flag when you want to apply threshold intervals. Each interval is specified by a pair of values in the wave Twave. The first element in each pair is the low value and the second element is the high value. Pixel values that lie outside all the specified intervals are set to 0.

References

The automatic thresholding method (/M=1) is described in: T. W. Ridler and S. Calvard, IEEE Transactions on Systems, Man and Cybernetics, SMC-8, 630-632, 1978.

The thresholding method used with /M=6 is described in: A.Z. Arifin and A Asano, "Image segmentation by histogram thresholding using hierarchical cluster analysis", Pattern Recognition Letters 27 (2006) 1515-1521.

See Also

ImageGenerateROIMask, ImageEdgeDetection

Image Processing