Skip to content

Relative Thresholding vTool#

The Relative Thresholding vTool allows you to segment images by creating a relative threshold that makes features in the images more distinguishable.

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.

If you use the ROI Creator vTool to specify a region of interest before thresholding, the Relative Thresholding vTool accepts the ROI data via its Roi input pin. In that case, thresholding is only performed on the region of interest.

The Region output of the Relative Thresholding vTool can also be used as Roi input for vTools with a Roi input pin. For more information, see the ROI Creator vTool topic.

Relative Thresholding vTool

How It Works#

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.

Relative Thresholding Input Image

Relative Thresholding Histogram Original 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.

Relative Thresholding Histogram Intermediate Image

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.

Relative Thresholding Segmentation Result

Info

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:

Relative Thresholding vTool Settings

  1. In the Recipe Management pane in the vTool Settings area, click Open Settings or double-click the vTool.
    The Relative Thresholding Basic dialog opens.
  2. Specify the filter size for creating the reference image.
  3. Specify a relative threshold.
  4. 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.

Inputs#

Image#

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.

Roi#

Accepts a region of interest from the ROI Creator vTool or any other vTool that outputs regions or rectangles. Multiple rectangles or regions are merged internally to form a single region of interest.

  • Data type: RectangleF, RectangleF Array, Region, Region Array

Outputs#

Region#

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

Typical Predecessors#

Typical Successors#