Skip to content

var_thresholdVarThresholdVarThresholdvar_thresholdvar_thresholdπŸ”—

Short descriptionπŸ”—

var_thresholdVarThresholdVarThresholdvar_thresholdvar_threshold β€” Threshold an image by local mean and standard deviation analysis.

SignatureπŸ”—

var_threshold( image Image, out region Region, extent.x MaskWidth, extent.y MaskHeight, number StdDevScale, number AbsThreshold, string LightDark )void VarThreshold( const HObject& Image, HObject* Region, const HTuple& MaskWidth, const HTuple& MaskHeight, const HTuple& StdDevScale, const HTuple& AbsThreshold, const HTuple& LightDark )static void HOperatorSet.VarThreshold( HObject image, out HObject region, HTuple maskWidth, HTuple maskHeight, HTuple stdDevScale, HTuple absThreshold, HTuple lightDark )def var_threshold( image: HObject, mask_width: int, mask_height: int, std_dev_scale: Union[int, float], abs_threshold: Union[int, float], light_dark: str ) -> HObject

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 )

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

HRegion HImage::VarThreshold( Hlong MaskWidth, Hlong MaskHeight, double StdDevScale, double AbsThreshold, const wchar_t* LightDark ) const (Windows only)

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_thresholdVarThreshold, it’s possible to select the pixels of the input Imageimageimage which

and

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

Hints for the input parametersπŸ”—

The calculationπŸ”—

Β 
(1) (2)

(1) Initial image. (2) Thresholded image (StdDevScalestdDevScalestd_dev_scale := 0.60.6, MaskWidthmaskWidthmask_width := 1515, MaskHeightmaskHeightmask_height := 1515, AbsThresholdabsThresholdabs_threshold := 1010). The following images visualize exemplary how the result along the blue arrow came to be.

var_thresholdVarThreshold selects from the input image Imageimageimage those regions Regionregionregion 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 MaskWidthmaskWidthmask_width x MaskHeightmaskHeightmask_height around each pixel \((x,y)\).

Let

  • \(g(x,y)\) be the gray value at position \((x,y)\) in the input Imageimageimage,

  • \(m(x,y)\) the corresponding mean gray value, and

  • \(d(x,y)\) the corresponding standard deviation in the mask around that pixel.

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

\(v(x,y) = max( \textrm{StdDevScale} * d(x,y),\textrm{AbsThreshold})\) for \(\textrm{StdDevScale} \ge 0\) or \(v(x,y) = min( \textrm{StdDevScale} * d(x,y), \textrm{AbsThreshold})\) for \(\textrm{StdDevScale} < 0\).

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

The standard deviation can be scaled with StdDevScalestdDevScalestd_dev_scale.

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

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

  • 'light'"light": \(g(x,y) \ge m(x,y) + v(x,y)\).

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

  • 'dark'"dark": \(g(x,y) \le m(x,y) - v(x,y)\).

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

    LightDarklightDarklight_dark = 'equal'"equal": \(m(x,y) - v(x,y) \le g(x,y) \le m(x,y) + v(x,y)\).

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

  • 'not_equal'"not_equal": \(m(x,y) - v(x,y) > g(x,y) \quad \lor \quad g(x,y) > m(x,y) + v(x,y)\).

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

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

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

AttentionπŸ”—

Note that filter operators may return unexpected results if an image with a reduced domain is used as input. Please refer to the chapter Filters.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on tuple level.

  • Automatically parallelized on domain level.

ParametersπŸ”—

Imageimageimage (input_object) singlechannelimage(-array) β†’ object (byte / int2 / int4 / uint2 / real)HObject (byte / int2 / int4 / uint2 / real)HImage (byte / int2 / int4 / uint2 / real)HObject (byte / int2 / int4 / uint2 / real)Hobject (byte / int2 / int4 / uint2 / real)

Input image.

Regionregionregion (output_object) region(-array) β†’ objectHObjectHRegionHObjectHobject *

Segmented regions.

MaskWidthmaskWidthmask_width (input_control) extent.x β†’ (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Mask width for mean and deviation calculation.

Default: 1515
Suggested values: 9, 11, 13, 159, 11, 13, 15
Restriction: MaskWidth>=1

MaskHeightmaskHeightmask_height (input_control) extent.y β†’ (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Mask height for mean and deviation calculation.

Default: 1515
Suggested values: 9, 11, 13, 159, 11, 13, 15
Restriction: MaskHeight>=1

StdDevScalestdDevScalestd_dev_scale (input_control) number β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[int, float]Htuple (double / Hlong)

Factor for the standard deviation of the gray values.

Default: 0.20.2
Suggested values: -0.2, -0.1, 0.1, 0.2-0.2, -0.1, 0.1, 0.2

AbsThresholdabsThresholdabs_threshold (input_control) number β†’ (real / integer)HTuple (double / Hlong)HTuple (double / int / long)Union[int, float]Htuple (double / Hlong)

Minimum gray value difference from the mean.

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

LightDarklightDarklight_dark (input_control) string β†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Threshold type.

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

ComplexityπŸ”—

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

ResultπŸ”—

var_thresholdVarThreshold 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'"no_object_result", 'empty_region_result'"empty_region_result", and 'store_empty_region'"store_empty_region" with set_systemSetSystem. If necessary, an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Alternatives

dyn_thresholdDynThreshold, thresholdThreshold

ReferencesπŸ”—

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

ModuleπŸ”—

Foundation