Skip to content

binary_thresholdBinaryThresholdBinaryThresholdbinary_thresholdbinary_thresholdπŸ”—

Short descriptionπŸ”—

binary_thresholdBinaryThresholdBinaryThresholdbinary_thresholdbinary_threshold β€” Segment an image using binary thresholding.

SignatureπŸ”—

binary_threshold( image Image, out region Region, string Method, string LightDark, out number UsedThreshold )void BinaryThreshold( const HObject& Image, HObject* Region, const HTuple& Method, const HTuple& LightDark, HTuple* UsedThreshold )static void HOperatorSet.BinaryThreshold( HObject image, out HObject region, HTuple method, HTuple lightDark, out HTuple usedThreshold )def binary_threshold( image: HObject, method: str, light_dark: str ) -> Tuple[HObject, Sequence[Union[str, int]]]

def binary_threshold_s( image: HObject, method: str, light_dark: str ) -> Tuple[HObject, Union[str, int]]Herror binary_threshold( const Hobject Image, Hobject* Region, const char* Method, const char* LightDark, Hlong* UsedThreshold )

Herror T_binary_threshold( const Hobject Image, Hobject* Region, const Htuple Method, const Htuple LightDark, Htuple* UsedThreshold )

HRegion HImage::BinaryThreshold( const HString& Method, const HString& LightDark, HTuple* UsedThreshold ) const

HRegion HImage::BinaryThreshold( const HString& Method, const HString& LightDark, Hlong* UsedThreshold ) const

HRegion HImage::BinaryThreshold( const char* Method, const char* LightDark, Hlong* UsedThreshold ) const

HRegion HImage::BinaryThreshold( const wchar_t* Method, const wchar_t* LightDark, Hlong* UsedThreshold ) const (Windows only)

HRegion HImage.BinaryThreshold( string method, string lightDark, out HTuple usedThreshold )

HRegion HImage.BinaryThreshold( string method, string lightDark, out int usedThreshold )

DescriptionπŸ”—

binary_thresholdBinaryThreshold segments a single-channel Imageimageimage using an automatically determined global threshold and returns the segmented region in Regionregionregion. This is, e.g., useful for the segmentation of characters on a homogeneously illuminated background. binary_thresholdBinaryThreshold also returns the used threshold in UsedThresholdusedThresholdused_threshold.

The used threshold is determined by the method that is given in Methodmethodmethod. Currently the operator provides the following two methods: 'max_separability'"max_separability" and 'smooth_histo'"smooth_histo". Both methods should only be used for images that have a bimodal histogram.

The method 'smooth_histo'"smooth_histo" provides the same functionality that has been provided by the operator bin_thresholdBinThreshold. The method 'max_separability'"max_separability" tends to determine smaller values for UsedThresholdusedThresholdused_threshold. Furthermore, it is less sensitive to thin isolated peaks in the histogram that are far from the rest of the spectrum and often, it is faster than 'smooth_histo'"smooth_histo".

Maximize separabilityπŸ”—

By selecting Methodmethodmethod = 'max_separability'"max_separability", automatic thresholding based on the gray-level histogram according to Otsu (see the paper in References) is invoked. The algorithm first calculates the histogram of the image and then uses statistical moments to find the optimal threshold \(T^{*}\) that divides the pixels into foreground and background and maximizes the separability between these two classes. This method is only available for byte and uint2 images.

Histogram smoothingπŸ”—

By selecting Methodmethodmethod = 'smooth_histo'"smooth_histo" binary_thresholdBinaryThreshold determines the threshold \(T^{*}\) in the following way: First, the relative histogram of the gray values is determined. Then, relevant minima are extracted from the histogram, which are used as parameters for a thresholding operation. In order to reduce the number of minima, the histogram is smoothed with a Gaussian, as in auto_thresholdAutoThreshold. The mask size is enlarged until there is only one minimum in the smoothed histogram. Then, the threshold \(T^{*}\) is set to the position of this minimum.

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 internal data level.

ParametersπŸ”—

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

Input Image.

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

Segmented output region.

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

Segmentation method.

Default: 'max_separability'"max_separability"
List of values: 'max_separability', 'smooth_histo'"max_separability", "smooth_histo"

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

Extract foreground or background?

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

UsedThresholdusedThresholdused_threshold (output_control) number(-array) β†’ (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)Sequence[Union[str, int]]Htuple (Hlong / char*)

Used threshold.

Combinations with other operatorsπŸ”—

Combinations

Possible successors

connectionConnection, select_shapeSelectShape, select_graySelectGray

Alternatives

auto_thresholdAutoThreshold, char_thresholdCharThreshold, local_thresholdLocalThreshold

See also

gray_histoGrayHisto, thresholdThreshold

ReferencesπŸ”—

N. Otsu, ``A threshold selection method from gray level histograms”, IEEE Trans. Syst. Man. Cybern., Vol. SMC-9, 62-66 (1979).

ModuleπŸ”—

Foundation