Relative Thresholding vTool#
The Relative Thresholding vTool segments the input image into a region that contains only the pixels with gray values above the threshold and with the polarity specified by you. Use Relative Thresholding to segment small, local features or when it's not possible to define a fixed threshold across the complete image to successfully segment the image, e.g., because the gray values of the background of the image vary greatly.
The Relative Thresholding vTool accepts an image via the Image input pin and outputs a single region via the Region output pin.
The following image shows a typical input image and the corresponding histogram. It shows that the gray value distribution is spread more or less evenly across the whole range. This typically stems from a continuous shading over the complete image.
In cases like this, it's not possible to find a suitable threshold to separate the object features from the rest of the image. Generally speaking, the gray values of the desired region are within the same range of gray values as the background region. Therefore, a separation of foreground and background pixels isn't possible.
The relative image employed by this vTool makes the target features more distinguishable. The following image shows the histogram of the relative image. You can see that the gray value distribution is similar to a normal distribution with a mean intensity of zero.
To create the relative image, the input image is smoothed by a square mean filter of the size specified in the vTool's settings. The result is the reference image.
The reference image is subtracted from the input image to create a relative image, which is the basis for segmentation decisions.
The Relative Threshold setting defines the boundaries for segmentation, i.e., the borders in the histogram between the darker to the similar part and between the similar to the lighter part.
The last step is to select a polarity to specify which part of the relative image is included in the output region. The following polarities are available:
- Darker: All pixels with a gray value lower than or equal to the negative threshold value are included in the output region.
- Lighter: All pixels with a gray value higher than or equal to the positive threshold value are included in the output region.
- Similar: All pixels in the central part of the histogram between the negative and the positive threshold are included in the output region.
- Darker of lighter: All pixels at the lower or the higher end of the distribution are included in the output region.
The result for the example image is shown below. The output region contains the desired features of the circuit board. If the result of Relative Thresholding is still noisy, using the Region Morphology vTool as a post-processing step may help to reduce the noise.
In order to detect local features, choose a filter size that is approximately three times larger than the smallest dimension of the feature.
If you want to use Relative Thresholding to segment larger objects, which fill more or less the whole image, choosing an appropriate filter size isn't possible. Therefore, you have to start by segmenting the borders of the target object. Afterwards, use the Region Morphology vTool to split the region followed by a region filling.
Configuring the vTool#
To configure the Relative Thresholding vTool:
- In the Recipe Management pane in the vTool Settings area, click Open Settings or double-click the vTool.
The Relative Thresholding dialog opens.
- Specify the filter size for creating the reference image.
- Specify a relative threshold.
- Select the desired polarity.
You can view the result of the thresholding in a pin data view. Here, you can select which outputs to display.
Accepts images directly from a Camera vTool or from a vTool that outputs images, e.g., the Image Format Converter vTool.
- Data type: Image
- Image format: 8-bit to 16-bit mono or color images. Color images are converted internally to mono images.
Returns a single region that includes only the pixels with gray values above the threshold and with the polarity specified by you.
- Data type: Region