MultiThreshold2 Method

NI Vision for Visual Basic

MultiThreshold2 Method

Syntax

CWIMAQVision.MultiThreshold2 SourceImage, DestImage, MultiThresholdData

Return Type

Long

On success, this method returns 0. On failure, this method returns a negative number.

Purpose

Thresholds an image into multiple classes. The method classifies each pixel into the last threshold range of which it is a member. If a pixel is not a member of any of the given ranges, the method sets it to 0. For example, given two threshold ranges

the method operates as follows:

Replaces pixel values below 80 with 0.

Replaces pixel values from 80 to 120 with 10.

Does not change pixel values from 121 to 200.

Replaces pixel values above 200 with 0.

Remarks

Use this method with U8, I16, and SGL images.

The threshold operations are performed in the order that the data is received from MultiThreshold Data. A pixel can be taken into account only once, even if the pixel is included in the threshold range of two different thresholds.

For example, consider the following MultiThresholdData input:

rangeMin rangeMax useNewValue newValue
80 150 TRUE 10
120 200 FALSE <ignored>
Item 1ThresholdRange.Min= 80, ThresholdRange.Max = 150, DoReplacement = TRUE, NewValue = 255.
Item 2ThresholdRange.Min = 120, ThresholdRange.Max = 200, DoReplacement = FALSE.

This example shows two threshold ranges with an overlap between 120 and 150. Therefore, the pixels between 120 and 150 are treated only by the second threshold. The following results occur after execution of this method:

  • Pixel values between 0 and 79 are replaced by 0.

  • Pixel values between 80 and 120 are replaced by 255.

  • Pixel values between 121 and 200 keep their original values.

  • Pixel values greater than 200 are set to 0.

Parameters

SourceImage As CWIMAQImage

The image to process.

DestImage As CWIMAQImage

The resulting image.

MultiThresholdData As CWIMAQMultiThresholdData

The data required to perform the multithreshold.

Example

Dim i As New CWIMAQImage
Dim thresholdData As New CWIMAQMultiThresholdData
 
'AutoThreshold the image in Viewer1 into 3 classes and store the 
'result in i
CWIMAQVision1.AutoThreshold CWIMAQViewer1.Image, i, 3, _
                            cwimaqATMethodCluster, _
                            thresholdData
    
'Use thresholdData result to MultiThreshold the Viewer inplace
CWIMAQVision1.MultiThreshold2 CWIMAQViewer1.Image, _
                              CWIMAQViewer1.Image, _
                              thresholdData

See Also

Threshold