threshVarLocal
Top  Previous  Next

threshVarLocal ( integer Input, integer Output, integer Channel, integer Window,
[, integer Invert =0 ] )  

Use this function to automatically separate objects of interest from the background by using the variance minimization adaptive technique. The method analyzes the histogram of the local neighborhood surrounding each pixel and tries to match it to a bimodal histogram, when each mode has approximately the same number of pixels. The threshold is locally set to include pixels with a minimum variance. For color images thresholding can be performed on the luminance, hue or saturation channel.

Parameters
 
Input  
 
An integer between 0 and 116 specifying the input image frame number. A value of 0 represents the DMA memory buffer of the video device. Values in the range of 100-116 correspond to hidden frames.  
 
Output  
 
An integer between 1 and 116 specifying the output image frame number. Values in the range of 100-116 correspond to hidden frames.  
 
Channel  
 
An enumerated integer specifying the color channel that will be used for histogram analysis and thresholding. Must be one of the following values:  
 
TH_LUMINANCE=0 – separate the objects of interest based on the intensity distribution.  
TH_HUE=1 – separate the objects of interest based on the color pigment distribution.  
TH_SATURATION=2 - separate the objects of interest based on the color saturation distribution.  
 
This parameter is disregarded for grayscale images.  
 
Window  
 
A positive integer specifying the size of the square window for the local histogram analysis. For better results this value should be comparable with the size of the largest object of interest in the image.  
 
Invert  
 
An optional boolean integer that defines if the foreground range should be inverted. Must be one of the following values:  
 
FALSE=0 – normal mode of thresholding. The pixels whose values are equal or above the calculated threshold level will be treated as foreground ones, while the pixels with values below the will be treated as background ones.  
TRUE=1 – inverted mode of thresholding. The pixels whose values are equal or above the calculated threshold level will be treated as background ones, while the pixels with values below the will be treated as foreground ones.  
Default value: FALSE  
 
Error flags

ERR_OK  
 
The flag set if successful.  
 
ERR_FAILED  
 
The flag set if failed.  
 
Remark
 
The outcome of this function is affected by the Histogram Preferences. Use setHistAttr to set the desired Sampling of the histogram and specify if the black or white pixels should be ignored in the histogram analysis.  

Example

This set of statements removes the dark background from a sample image:  
 
GrabIm(1)  
threshVarLocal  (1, 2,  TH_LUMINANCE, 32)