ClassesClassesClassesClasses | | | | Operators

local_thresholdlocal_thresholdLocalThresholdlocal_thresholdLocalThresholdLocalThreshold (Operator)


local_thresholdlocal_thresholdLocalThresholdlocal_thresholdLocalThresholdLocalThreshold — Segment an image using local thresholding.


local_threshold(Image : Region : Method, LightDark, GenParamName, GenParamValue : )

Herror local_threshold(const Hobject Image, Hobject* Region, const char* Method, const char* LightDark, const char* GenParamName, const Hlong GenParamValue)

Herror T_local_threshold(const Hobject Image, Hobject* Region, const Htuple Method, const Htuple LightDark, const Htuple GenParamName, const Htuple GenParamValue)

Herror local_threshold(Hobject Image, Hobject* Region, const HTuple& Method, const HTuple& LightDark, const HTuple& GenParamName, const HTuple& GenParamValue)

HRegion HImage::LocalThreshold(const HTuple& Method, const HTuple& LightDark, const HTuple& GenParamName, const HTuple& GenParamValue) const

HRegionArray HImageArray::LocalThreshold(const HTuple& Method, const HTuple& LightDark, const HTuple& GenParamName, const HTuple& GenParamValue) const

void LocalThreshold(const HObject& Image, HObject* Region, const HTuple& Method, const HTuple& LightDark, const HTuple& GenParamName, const HTuple& GenParamValue)

HRegion HImage::LocalThreshold(const HString& Method, const HString& LightDark, const HTuple& GenParamName, const HTuple& GenParamValue) const

HRegion HImage::LocalThreshold(const HString& Method, const HString& LightDark, const HString& GenParamName, Hlong GenParamValue) const

HRegion HImage::LocalThreshold(const char* Method, const char* LightDark, const char* GenParamName, Hlong GenParamValue) const

void HOperatorSetX.LocalThreshold(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*Region, [in] VARIANT Method, [in] VARIANT LightDark, [in] VARIANT GenParamName, [in] VARIANT GenParamValue)

IHRegionX* HImageX.LocalThreshold(
[in] BSTR Method, [in] BSTR LightDark, [in] VARIANT GenParamName, [in] VARIANT GenParamValue)

static void HOperatorSet.LocalThreshold(HObject image, out HObject region, HTuple method, HTuple lightDark, HTuple genParamName, HTuple genParamValue)

HRegion HImage.LocalThreshold(string method, string lightDark, HTuple genParamName, HTuple genParamValue)

HRegion HImage.LocalThreshold(string method, string lightDark, string genParamName, int genParamValue)


local_thresholdlocal_thresholdLocalThresholdlocal_thresholdLocalThresholdLocalThreshold segments a single-channel image ImageImageImageImageImageimage using the thresholding method given in MethodMethodMethodMethodMethodmethod and returns the segmented region in RegionRegionRegionRegionRegionregion. Currently the operator offers only the Method 'adapted_std_deviation'"adapted_std_deviation""adapted_std_deviation""adapted_std_deviation""adapted_std_deviation""adapted_std_deviation". This algorithm is a text binarization technique and provides good results for document images.


By selecting MethodMethodMethodMethodMethodmethod = 'adapted_std_deviation'"adapted_std_deviation""adapted_std_deviation""adapted_std_deviation""adapted_std_deviation""adapted_std_deviation", a locally adaptive thresholding based on local mean and standard deviation according to Sauvola (see the paper in References) is invoked. The algorithm is able to segment document images even if they are degraded, e.g., due to inhomogeneous illumination or noise. It enables text binarization on an inhomogeneous background by taking into account the local contrast.

For a segmentation of the dark foreground (see parameter LightDarkLightDarkLightDarkLightDarkLightDarklightDark), for a pixel at position (r,c), a local threshold T(r,c) is calculated within a window of size mask_size x mask_size (see the generic parameter 'mask_size'"mask_size""mask_size""mask_size""mask_size""mask_size") as follows:

where is the local mean value within the window and denotes the corresponding standard deviation. The parameter R (see 'range'"range""range""range""range""range") is the assumed maximum value of the standard deviation (R = 128 for byte images) and k (see 'scale'"scale""scale""scale""scale""scale") a parameter that controls how much the threshold value T(r,c) differs from the mean value . If there is high contrast in the neighborhood of a point (r,c) the standard deviation has a value close to R which yields a threshold value T(r,c) close to the local mean . If the contrast is low, the local threshold is below the local mean value. For dark text on light background containing also darker regions, this lower threshold enables the segmentation of the text even in darker areas.

The parameter LightDarkLightDarkLightDarkLightDarkLightDarklightDark controls, whether light or dark structures are segmented.

By setting GenParamNameGenParamNameGenParamNameGenParamNameGenParamNamegenParamName to one of the following values, additional parameters specific for the 'adapted_std_deviation' method can be set with GenParamValueGenParamValueGenParamValueGenParamValueGenParamValuegenParamValue:


specifies the mask size, i.e., the size of the neighborhood in which the local threshold is calculated. The smaller the window size the thinner the segmented strokes. 'mask_size'"mask_size""mask_size""mask_size""mask_size""mask_size" must be set to a value that is larger than the stroke width of the characters or structures to be segmented. If 'mask_size'"mask_size""mask_size""mask_size""mask_size""mask_size" is even, the next larger odd value is used.

Suggested values: 15 (default), 21, 31


sets the parameter k ( ), that controls how much the threshold value differs from the local mean value. Use smaller values for 'scale'"scale""scale""scale""scale""scale" to also segment structures with a lower contrast to their background. Use larger values to suppress clutter.

Suggested values: 0.2 (default), 0.3, 0.5


sets the maximum assumed value of standard deviation R . This parameter should be adapted based on the expected gray value range. As a rule of thumb, the value for 'range'"range""range""range""range""range" can be set to , where MinGray and MaxGray are the minimum and maximum gray values in the image, which can be determined with min_max_graymin_max_grayMinMaxGraymin_max_grayMinMaxGrayMinMaxGray.

Suggested values: 128 (default) for byte images, 32767.5 (default) for uint2 images



ImageImageImageImageImageimage (input_object)  singlechannelimage(-array) objectHImageHImageHImageHImageXHobject (byte / uint2)

Input Image.

RegionRegionRegionRegionRegionregion (output_object)  region(-array) objectHRegionHRegionHRegionHRegionXHobject *

Segmented output region.

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

Segmentation method.

Default value: 'adapted_std_deviation' "adapted_std_deviation" "adapted_std_deviation" "adapted_std_deviation" "adapted_std_deviation" "adapted_std_deviation"

List of values: 'adapted_std_deviation'"adapted_std_deviation""adapted_std_deviation""adapted_std_deviation""adapted_std_deviation""adapted_std_deviation"

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

Extract foreground or background?

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

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

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

List of generic parameter names.

Default value: []

List of values: 'mask_size'"mask_size""mask_size""mask_size""mask_size""mask_size", 'range'"range""range""range""range""range", 'scale'"scale""scale""scale""scale""scale"

GenParamValueGenParamValueGenParamValueGenParamValueGenParamValuegenParamValue (input_control)  attribute.value(-array) HTupleHTupleHTupleVARIANTHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double) (Hlong / double) (Hlong / double)

List of generic parameter values.

Default value: []

Suggested values: 0.2, 15, 30, 128.0

Possible Successors

connectionconnectionConnectionconnectionConnectionConnection, select_shapeselect_shapeSelectShapeselect_shapeSelectShapeSelectShape, select_grayselect_graySelectGrayselect_graySelectGraySelectGray


auto_thresholdauto_thresholdAutoThresholdauto_thresholdAutoThresholdAutoThreshold, binary_thresholdbinary_thresholdBinaryThresholdbinary_thresholdBinaryThresholdBinaryThreshold, char_thresholdchar_thresholdCharThresholdchar_thresholdCharThresholdCharThreshold

See also

gray_histogray_histoGrayHistogray_histoGrayHistoGrayHisto, thresholdthresholdThresholdthresholdThresholdThreshold


J. Sauvola, M. Pietikäinen, “Adaptive document image binarization", Pattern Recognition, 33, 225-236 (2000)



ClassesClassesClassesClasses | | | | Operators