Threshold

List of Operators ↓

This chapter describes threshold operators.

Concept of Threshold Operators

One way to perform a segmentation of an image is to use threshold operators. In doing so, regions that fulfill a certain threshold condition, depending on gray values, are determined within an image.

In order to fit different tasks and image properties there is a set of threshold operators provided.

The following paragraphs give an overview of the operators by differentiating them into histogram-based and local methods and having a closer look at the most important ones.

Histogram-based Threshold Operators

Histogram-based threshold segmentation does not take the position but only the pixel value into account. Therefore thresholds are determined by adjusting them to the histogram of an image.

Threshold

By using thresholdthresholdThresholdThresholdThresholdthreshold, you can select all pixels within user set gray value intervals.

(1) (2) (3)
(1) Input image, (2) histogram of the input image with manually determined thresholds MinGrayMinGrayMinGrayMinGrayminGraymin_gray and MaxGrayMaxGrayMaxGrayMaxGraymaxGraymax_gray, (3) resulting segmentation of the input image.

The operator fast_thresholdfast_thresholdFastThresholdFastThresholdFastThresholdfast_threshold also works with two manually determined thresholds but uses another computing algorithm.

Binary Threshold

To divide your image into light and dark regions, binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdBinaryThresholdbinary_threshold automatically computes a threshold to separate foreground from background.

(1) (2) (3)
(1) Input image, (2) histogram of the input image with automatically determined binary threshold, (3) resulting segmentation of the input image.

A segmentation using threshold_sub_pixthreshold_sub_pixThresholdSubPixThresholdSubPixThresholdSubPixthreshold_sub_pix also divides the image into foreground and background, but puts out the separating border with sub-pixel accuracy. The threshold has to be set manually.

Automatic Threshold

auto_thresholdauto_thresholdAutoThresholdAutoThresholdAutoThresholdauto_threshold computes local minima in the image histogram to determine thresholds. By smoothing the histogram you have influence on the number of classes found in the input image.

(1) (2) (3) (4)
(1) Slightly smoothed histogram, (2) results in higher number of local minima, (3) with further smoothing, (4) number of local minima decreases.
(1) (2) (3)
(1) Input image, (2) four classes are extracted from slightly smoothed histogram, (3) whereas in this case a further smoothed histogram results in two regions.

Use histo_to_threshhisto_to_threshHistoToThreshHistoToThreshHistoToThreshhisto_to_thresh to get the gray values of local minima in the histogram.

Character Threshold

To do a segmentation of dark text on light background, char_thresholdchar_thresholdCharThresholdCharThresholdCharThresholdchar_threshold is a useful tool. The maximum peak in the histogram corresponds to the light background. Assuming the text is darker than the background, you examine the smoothed histogram left of the maximum. The parameter PercentPercentPercentPercentpercentpercent determines how far from the maximum the threshold is set, taking the frequencies of the gray values into account.

(1) (2)
(3) (4)
(1) Input image, (2) histogram is smoothed and global maximum is identified, (3) the parameter PercentPercentPercentPercentpercentpercent determines threshold left of the maximum, (4) resulting image.
Dual-Threshold

Subtracting an image from another or using an edge detecting operator like laplace_of_gausslaplace_of_gaussLaplaceOfGaussLaplaceOfGaussLaplaceOfGausslaplace_of_gauss usually leads to negative values in the resulting image. The operator dual_thresholddual_thresholdDualThresholdDualThresholdDualThresholddual_threshold is suited for the segmentation of signed images while also taking minimum region size into account.

Histogram of a signed image with ThresholdThresholdThresholdThresholdthresholdthreshold (inner boundaries) and MinGrayMinGrayMinGrayMinGrayminGraymin_gray. Pixels are only selected if they fulfill the conditions regarding gray values and region size.
(1) (2)
(1) Signed input image (created with sub_imagesub_imageSubImageSubImageSubImagesub_image), (2) result after applying a dual threshold.

Local Threshold Operators

Unlike histogram-based threshold operators, a local threshold also takes position or neighborhood of pixels into account to assign them to the appropriate region. Instead of global thresholds that are applied to each pixel, it is sometimes be useful to adapt the threshold to local features of the image.

Local Threshold

local_thresholdlocal_thresholdLocalThresholdLocalThresholdLocalThresholdlocal_threshold takes the local mean and standard deviation into account and computes an individual threshold for each pixel. The size of the neighborhood is set by the user. This operator is especially suited for the segmentation of text, when lighting conditions or the background are not homogeneous.

(1) (2)
(3) (4)
(1) Input image, (2) segmentation with global thresholds does not choose the desired text solely, (3) adapting the threshold to the neighborhood of each pixel individually, (4) segmentation of the text.

The operator var_thresholdvar_thresholdVarThresholdVarThresholdVarThresholdvar_threshold works in a similar way, except it selects those points of the image that fulfill specified conditions regarding their local standard deviation and brightness.

Dynamic Threshold

With dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold you can inspect the differences between images. Usually the input image and a filtered version, e.g. the mean of the image, are compared pixel by pixel. The parameter LightDarkLightDarkLightDarkLightDarklightDarklight_dark is used to determine what kind of changes in the image are relevant. The sensitivity of the operator is controlled by the parameter OffsetOffsetOffsetOffsetoffsetoffset.

(1) (2)
(3) (4)
(1) Input image, (2) segmentation of scratches with global threshold is not possible due to inhomogeneous lighting conditions, (3) inspection of the gray value difference between the original image (left) and mean of the image (middle) pixel by pixel to segment regions (right) exceeding OffsetOffsetOffsetOffsetoffsetoffset (image detail), (4) result after selecting wanted regions. For more detail have a look at the example surface_scratch.hdev.

A similar operator is check_differencecheck_differenceCheckDifferenceCheckDifferenceCheckDifferencecheck_difference. The operator displays the absolute differences between two images. It is especially suited for change detection of consecutively acquired images.

Zero Crossing Threshold

Operators like laplace_of_gausslaplace_of_gaussLaplaceOfGaussLaplaceOfGaussLaplaceOfGausslaplace_of_gauss that are used for edge detection return signed images, where edges are located at the zero crossings. zero_crossingzero_crossingZeroCrossingZeroCrossingZeroCrossingzero_crossing and zero_crossing_sub_pixzero_crossing_sub_pixZeroCrossingSubPixZeroCrossingSubPixZeroCrossingSubPixzero_crossing_sub_pix can be used to extract those edges, taking the individual 4-neighborhood into account.