threshold
Top  Previous  Next

threshold ( integer Input, integer Output, integer Mode, floating& Min [,
floating& Max =maxpix, integerBinary= 1, integer Invert = 0 ] )  

Use this function to separate objects of interest from the background by specifying the range of pixel intensities that represents the foreground.

The segmented image can be created as a binary one or assigned the same type as the input image. The function can be called in the automatic or interactive modes. In the interactive modes the user can adjust the range of intensities for the foreground pixels interactively and preview the segmented areas in real time, as the color overlay highlights the objects of interest in the input image.

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. If the function is called in the interactive mode (M_DIALOG or M_MOUSE), only visible frames (1-99) can be used.  
 
Output  
 
An integer between 1 and 116 specifying the output image frame number. Values in the range of 100-116 correspond to hidden frames.  
 
Mode  
 
An enumerated integer that describes the mode to use. Must be one of the following values:  
 
M_PRESET=0 – immediately applies the function to the input image using the values specified by the Min and Max parameters.  
M_DIALOG=1 – opens the Binary Threshold dialog that lets the user adjust the foreground range manually by moving the sliders on the dialog picking up foreground levels with the Sampling tool. As the sliders are moved, the color overlay of the input image expands or contracts, highlighting the foreground pixels.  
M_MOUSE=2 – activates the mouse mode that lets the user interactively select the threshold ranges with a mouse. Moving the mouse upward and downward widens or narrows the foreground range respectively. Moving the mouse rightward or leftward raises or lowers the foreground range respectively. To apply the changes and exit the function, press the left mouse button. To exit the function without applying the changes to the image, press the right mouse button.  
 
Min, Max  
 
Floating arguments specifying the minimum and maximum levels of the thresholding range. A value of Max must be greater than a value of Min, and both must be in the range of pixel values allowable for the input image type. If Max is omitted, the function will work in the one-level mode assuming that Max is equal to the maximum permitted pixel value for the given image type. If the function is called in the interactive mode (M_DIALOG or M_MOUSE), the variables will return interactively selected levels.  
 
Binary  
 
An optional boolean integer that defines the type of the output image. Must be one of the following values:  
 
FALSE=0 – the output image will be of the same type as the input one. The foreground pixels will be transferred into the output image unchanged, while the pixels with values outside the specified range will be assigned the black level.  
TRUE=1 – the output image will be created as a binary one. A binary image is an image of the multiphase type that contains only two phases, 0 and 1. The foreground pixels whose values fall within the specified range will be converted into 1s, while the background pixels with values outside the range will be set to 0s.  
Default value: TRUE  
 
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 fall within the range between Min and Max will be treated as foreground ones, while the pixels with values outside the range will be treated as background ones. If only Min is specified, the pixels with values equal to Min and above will be treated as foreground ones.  
TRUE=1 – inverted mode of thresholding. The pixels whose values fall within the range between the minimum and maximum levels will be treated as background ones, while the pixels with values outside the range will be treated as foreground ones. If only Min is specified, the pixels with values less than Min 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.  
 
ERR_CANCEL=-2  
 
The flag set if the function cancelled in the interactive mode.  

Example

This set of statements performs thresholding of a captured image using the dialog mode and outputs interactively selected levels to the terminal window.  
 
grabIm (1)  
threshold (1, 2, M_DIALOG, Lev1, Lev2)  
print "Foreground range:"  
print "Level1=", Lev1  
print "Level2=", Lev2  
 
Remarks

For more information on the Binary Threshold dialog box, refer to ImageWarp User's Guide.