ClassesClassesClassesClasses | | | | Operators

var_thresholdvar_thresholdVarThresholdvar_thresholdVarThresholdVarThreshold (Operator)

Name

var_thresholdvar_thresholdVarThresholdvar_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 VarThreshold(const HObject& Image, HObject* Region, const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& StdDevScale, const HTuple& AbsThreshold, const HTuple& LightDark)

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

HRegion HImage::VarThreshold(Hlong MaskWidth, Hlong MaskHeight, double StdDevScale, double AbsThreshold, const HString& LightDark) const

HRegion HImage::VarThreshold(Hlong MaskWidth, Hlong MaskHeight, double StdDevScale, double AbsThreshold, const char* 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

With var_thresholdvar_thresholdVarThresholdvar_thresholdVarThresholdVarThreshold, it's possible to select the pixels of the input ImageImageImageImageImageimage which

and

Thus, it is possible to segment regions on inhomogeneous, noisy, or unevenly illuminated backgrounds.

Hints for the input parameters

MaskWidth, MaskHeight

The size of the filter mask defined by MaskWidthMaskWidthMaskWidthMaskWidthMaskWidthmaskWidth and MaskHeightMaskHeightMaskHeightMaskHeightMaskHeightmaskHeight determines the maximum size of the objects to be segmented. However, if the mask is chosen too large, objects that are very close might be merged.

(1) (2)
(3) (4)
(1) Original image; the goal is to count the vertical lines. (2) MaskWidthMaskWidthMaskWidthMaskWidthMaskWidthmaskWidth := 12, MaskHeightMaskHeightMaskHeightMaskHeightMaskHeightmaskHeight := 12, StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale := 0.1, all vertical lines are segmented correctly. (3) If the mask size is chosen too low (3), the desired regions are not selected properly. (4) If the mask size is too high (40), objects that are very close might be merged.

If MaskWidthMaskWidthMaskWidthMaskWidthMaskWidthmaskWidth or MaskHeightMaskHeightMaskHeightMaskHeightMaskHeightmaskHeight is even, the next larger odd value is used. Altogether, a value of 3 can be considered the minimum sensible value.

StdDevScale

The local standard deviation is used as a measure of noise in the image. It can be scaled by StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale to reflect the desired sensitivity. A higher value means that only pixels that are very different from their surrounding are selected.

For the parameter StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale 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.

(1) (2)
(1) If StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale is too high (1.3), the operator is 'picky'; only pixels that are very similar to their surrounding are selected. (2) If StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale is too low (-0.3), too many pixels that are somewhat similar to their surrounding are incorrectly selected.

AbsThreshold

In homogeneous areas of an image, the standard deviation is low; thus, the influence of single gray values is high. To reduce the sensitivity of the operator in homogeneous areas, it's possible to adjust AbsThresholdAbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold. Thus, small gray value changes in homogeneous surroundings can be ignored. Note that for negative values of StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale, AbsThresholdAbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold should also be chosen negative.

LightDark

'light'"light""light""light""light""light" or 'dark'"dark""dark""dark""dark""dark" returns all pixels that are lighter or darker than their surrounding, respectively. 'equal'"equal""equal""equal""equal""equal" returns all pixels that are not selected by either option, i.e. the pixels that are relatively equal to their surrounding. 'not_equal'"not_equal""not_equal""not_equal""not_equal""not_equal" returns the combined results of 'light'"light""light""light""light""light" and 'dark'"dark""dark""dark""dark""dark", i.e., all pixels that differ from their surrounding.

The calculation

(1) (2)
(1) Initial image. (2) Thresholded image (StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale := 0.6, MaskWidthMaskWidthMaskWidthMaskWidthMaskWidthmaskWidth := 15, MaskHeightMaskHeightMaskHeightMaskHeightMaskHeightmaskHeight := 15, AbsThresholdAbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold := 10). The following images visualize exemplary how the result along the blue arrow came to be.

var_thresholdvar_thresholdVarThresholdvar_thresholdVarThresholdVarThreshold selects from the input image ImageImageImageImageImageimage those regions RegionRegionRegionRegionRegionregion in which the pixels fulfill a threshold condition. The threshold is calculated from the mean gray value and the standard deviation in a local mask of size MaskWidthMaskWidthMaskWidthMaskWidthMaskWidthmaskWidth x MaskHeightMaskHeightMaskHeightMaskHeightMaskHeightmaskHeight around each pixel (x,y).

Let

The original gray values, the corresponding mean gray values, and the corresponding standard deviation in the mask around these pixels.

Then, the variable threshold v(x,y) is defined as

or

Interpretation: For a positive StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale, each pixel is analyzed. It is determined whether the user-defined AbsThresholdAbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold or the scaled standard deviation is greater. The bigger value is chosen as variable threshold v(x,y). For a negative StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale, the corresponding smaller value is chosen.

The standard deviation can be scaled with StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale.

The variable threshold is chosen based on the scaled standard deviation and AbsThresholdAbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold.

Which pixels are chosen based on the variable threshold is defined by the parameter LightDarkLightDarkLightDarkLightDarkLightDarklightDark:

LightDarkLightDarkLightDarkLightDarkLightDarklightDark = 'light'"light""light""light""light""light":

Interpretation: If the pixel is brighter by v(x,y) than its surrounding, it is selected.

LightDarkLightDarkLightDarkLightDarkLightDarklightDark = 'dark'"dark""dark""dark""dark""dark":

Interpretation: If the pixel is darker by v(x,y) than its surrounding, it is selected.

LightDarkLightDarkLightDarkLightDarkLightDarklightDark = 'equal'"equal""equal""equal""equal""equal":

Interpretation: Select exactly those pixels that are not selected by 'light'"light""light""light""light""light" and 'dark'"dark""dark""dark""dark""dark", i.e., the pixels that are relatively equal to their surrounding.

LightDarkLightDarkLightDarkLightDarkLightDarklightDark = 'not_equal'"not_equal""not_equal""not_equal""not_equal""not_equal":

Interpretation: Select all pixels of 'light'"light""light""light""light""light" and 'dark'"dark""dark""dark""dark""dark", i.e., all pixels that differ by v(x,y) from their surrounding.

'light'"light""light""light""light""light" and 'dark'"dark""dark""dark""dark""dark" are calculated based on the corresponding mean gray value and the variable threshold.

For example, if 'dark'"dark""dark""dark""dark""dark" is selected, all pixels where the 'Dark' curve is above the 'GrayValues' curve would be selected.

Attention

This operator may return unexpected results if an image with a reduced domain is used as input. Please refer to the chapter Filters.

Parallelization

Parameters

ImageImageImageImageImageimage (input_object)  singlechannelimage(-array) objectHImageHImageHImageHImageXHobject (byte / int2 / int4 / uint2 / real)

Input image.

RegionRegionRegionRegionRegionregion (output_object)  region(-array) objectHRegionHRegionHRegionHRegionXHobject *

Segmented regions.

MaskWidthMaskWidthMaskWidthMaskWidthMaskWidthmaskWidth (input_control)  extent.x HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Mask width for mean and deviation calculation.

Default value: 15

Suggested values: 9, 11, 13, 15

Restriction: MaskWidth >= 1

MaskHeightMaskHeightMaskHeightMaskHeightMaskHeightmaskHeight (input_control)  extent.y HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Mask height for mean and deviation calculation.

Default value: 15

Suggested values: 9, 11, 13, 15

Restriction: MaskHeight >= 1

StdDevScaleStdDevScaleStdDevScaleStdDevScaleStdDevScalestdDevScale (input_control)  number HTupleHTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (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

AbsThresholdAbsThresholdAbsThresholdAbsThresholdAbsThresholdabsThreshold (input_control)  number HTupleHTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong) (double / Hlong)

Minimum gray value difference from the mean.

Default value: 2

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

LightDarkLightDarkLightDarkLightDarkLightDarklightDark (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Threshold type.

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

List of values: 'dark'"dark""dark""dark""dark""dark", 'equal'"equal""equal""equal""equal""equal", 'light'"light""light""light""light""light", 'not_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_thresholdVarThresholdvar_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_thresholdDynThresholddyn_thresholdDynThresholdDynThreshold, thresholdthresholdThresholdthresholdThresholdThreshold

References

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

Module

Foundation


ClassesClassesClassesClasses | | | | Operators