threshWater
Top  Previous  Next

threshWater ( integer Input, integer Output, integer Channel, integer Phases, integer Filter,
integer Width [, integer Invert =0 ] [,floating& Lev1, floating& Lev2 ] … )  

Use this function to automatically segment the image into several phases by searching for minimums in an image histogram. The function treats the histogram as a topographic relief and finds the deepest "valleys" in it. The located levels of intensity are used as thresholds to segment the image into selected number of phases. Before the minimum search procedure is applied, the histogram is smoothed using a selected filter. For color images thresholding can be performed on the luminance, hue or saturation channel. The function creates a multiphase output image and returns calculated thresholds.

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.  
 
Phases  
 
An integer between 1 and 16 specifying the amount of phases into which the input image will be segmented. Depending on a value of Phases, the function will expect a corresponding number of Lev arguments at the end of the parameters' list.  
 
Filter  
 
An enumerated integer specifying the type of a filter used for smoothing the histogram prior to the distribution analysis. Must be one of the following values:  
 
TH_OPEN=0 – apply the morphological opening to the histogram array.  
TH_MEDIAN=1 – apply the median filter to the histogram array.  
 
Width     
 
A positive integer between 1 and 32 specifying the width of the filter window used for smoothing the histogram.  
 
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 minimum calculated threshold 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 maximum calculated threshold will be treated as background ones, while the pixels with values below the will be treated as foreground ones.  
Default value: FALSE  
 
Lev1, Lev2,…  
 
Optional floating variables that return the levels calculated from the histogram analysis and used for the segmentation.  

Error flags

ERR_OK  
 
The flag set if successful.  
 
ERR_FAILED  
 
The flag set if failed.  
 
Example

This set of statements segments a sample image into several phases using the watershed threshold:  
 
setCurDir("samples")  
loadIm (1,"sample8.iwd")  
threshWater (1, 2 , TH_LUMINANCE, 4, TH_MEDIAN, 5)  
 
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.