HALCON Reference Manual 10.0.2
Table of Contents / Segmentation / Threshold ClassesClassesClasses | | | Operators

var_thresholdvar_thresholdvar_thresholdVarThresholdVarThreshold (Operator)

Name

var_thresholdvar_thresholdvar_thresholdVarThresholdVarThreshold — Threshold an image by local mean and standard deviation analysis.

Signature

var_threshold(Image : Region : MaskWidth, MaskHeight, StdDevScale, AbsThreshold, LightDark : )

Herror var_threshold(const Hobject Image, Hobject* Region, const Hlong MaskWidth, const Hlong MaskHeight, double StdDevScale, double AbsThreshold, const char* LightDark)

Herror T_var_threshold(const Hobject Image, Hobject* Region, const Htuple MaskWidth, const Htuple MaskHeight, const Htuple StdDevScale, const Htuple AbsThreshold, const Htuple LightDark)

Herror var_threshold(Hobject Image, Hobject* Region, const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& StdDevScale, const HTuple& AbsThreshold, const HTuple& LightDark)

HRegion HImage::VarThreshold(const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& StdDevScale, const HTuple& AbsThreshold, const HTuple& LightDark) const

HRegionArray HImageArray::VarThreshold(const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& StdDevScale, const HTuple& AbsThreshold, const HTuple& LightDark) const

void HOperatorSetX.VarThreshold(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*Region, [in] VARIANT MaskWidth, [in] VARIANT MaskHeight, [in] VARIANT StdDevScale, [in] VARIANT AbsThreshold, [in] VARIANT LightDark)

IHRegionX* HImageX.VarThreshold(
[in] Hlong MaskWidth, [in] Hlong MaskHeight, [in] VARIANT StdDevScale, [in] VARIANT AbsThreshold, [in] BSTR LightDark)

static void HOperatorSet.VarThreshold(HObject image, out HObject region, HTuple maskWidth, HTuple maskHeight, HTuple stdDevScale, HTuple absThreshold, HTuple lightDark)

HRegion HImage.VarThreshold(int maskWidth, int maskHeight, HTuple stdDevScale, HTuple absThreshold, string lightDark)

HRegion HImage.VarThreshold(int maskWidth, int maskHeight, double stdDevScale, double absThreshold, string lightDark)

Description

The operator var_thresholdvar_thresholdvar_thresholdVarThresholdVarThreshold selects from the input image ImageImageImageImageimage those regions RegionRegionRegionRegionregion in which the pixels fulfill a threshold condition. The threshold is calculated from the mean gray value and the standard deviation in a local window of size MaskWidthMaskWidthMaskWidthMaskWidthmaskWidth x MaskHeightMaskHeightMaskHeightMaskHeightmaskHeight around each pixel (x,y). If MaskWidthMaskWidthMaskWidthMaskWidthmaskWidth or MaskHeightMaskHeightMaskHeightMaskHeightmaskHeight is even, the next larger odd value is used. The mask window should be greater than the image features to be segmented and it should comprise at least three pixels.

Let g(x,y) be the gray value at position (x,y) in the input image ImageImageImageImageimage and m(x,y) and d(x,y) the corresponding mean and standard deviation of the gray values in the window around that pixel and

  v(x,y) = max( StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale * d(x,y),AbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold)
  for StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale >= 0

or

  v(x,y) = min( StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale * d(x,y),AbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold)
  for $StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale < 0$.

The standard deviation is used as a measure of noise in the image and scaled by StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale to reflect the desired sensitivity. The threshold condition is determined by the parameter LightDarkLightDarkLightDarkLightDarklightDark:

LightDarkLightDarkLightDarkLightDarklightDark = 'light'"light""light""light""light":

  g(x,y) >= m(x,y) + v(x,y).

LightDarkLightDarkLightDarkLightDarklightDark = 'dark'"dark""dark""dark""dark":

  g(x,y) <= m(x,y) - v(x,y).

LightDarkLightDarkLightDarkLightDarklightDark = 'equal'"equal""equal""equal""equal":

  m(x,y) - v(x,y) <= g(x,y)
      <= m(x,y) + v(x,y).

LightDarkLightDarkLightDarkLightDarklightDark = 'not_equal'"not_equal""not_equal""not_equal""not_equal":

  m(x,y) - v(x,y) > g(x,y)   or   g(x,y) < m(x,y) + v(x,y).

All pixels fulfilling the above condition are aggregated into the resulting region RegionRegionRegionRegionregion.

For the parameter StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale values between -1.0 and 1.0 are sensible choices, with 0.2 as a suggested value. If the parameter is too high or too low, an empty or full region may be returned. The parameter AbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold places an additional threshold on StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale*dev(x,y). If StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale*dev(x,y) is below AbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold for positive values of StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale or above for negative values StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale, AbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold is taken instead.

Parallelization

Parameters

ImageImageImageImageimage (input_object)  singlechannelimage(-array) objectHImageHImageHImageXHobject (byte / int2 / int4 / uint2 / real)

Input image.

RegionRegionRegionRegionregion (output_object)  region(-array) objectHRegionHRegionHRegionXHobject *

Segmented regions.

MaskWidthMaskWidthMaskWidthMaskWidthmaskWidth (input_control)  extent.x HTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong)

Mask width for mean and deviation calculation.

Default value: 15

Suggested values: 9, 11, 13, 15

Restriction: MaskWidth >= 1

MaskHeightMaskHeightMaskHeightMaskHeightmaskHeight (input_control)  extent.y HTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong)

Mask height for mean and deviation calculation.

Default value: 15

Suggested values: 9, 11, 13, 15

Restriction: MaskHeight >= 1

StdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale (input_control)  number HTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong)

Factor for the standard deviation of the gray values.

Default value: 0.2

Suggested values: -0.2, -0.1, 0.1, 0.2

AbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold (input_control)  number HTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong)

Minimum gray value difference from the mean.

Default value: 2

Suggested values: -2, -1, 0, 1, 2

LightDarkLightDarkLightDarkLightDarklightDark (input_control)  string HTupleHTupleVARIANTHtuple (string) (string) (char*) (BSTR) (char*)

Threshold type.

Default value: 'dark' "dark" "dark" "dark" "dark"

List of values: 'dark'"dark""dark""dark""dark", 'light'"light""light""light""light", 'equal'"equal""equal""equal""equal", 'not_equal'"not_equal""not_equal""not_equal""not_equal"

Complexity

Let A be the area of the input region, then the runtime is O(A).

Result

var_thresholdvar_thresholdvar_thresholdVarThresholdVarThreshold returns 2 (H_MSG_TRUE) if all parameters are correct. The behavior with respect to the input images and output regions can be determined by setting the values of the flags 'no_object_result', 'empty_region_result', and 'store_empty_region' with set_system. If necessary, an exception is raised.

Alternatives

dyn_thresholddyn_thresholddyn_thresholdDynThresholdDynThreshold, thresholdthresholdthresholdThresholdThreshold

References

W.Niblack, ”An Introduction to Digital Image Processing”, Page 115-116, Englewood Cliffs, N.J., Prentice Hall, 1986

Module

Foundation


Table of Contents / Segmentation / Threshold ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH