Binarize adaptively🔗

Transforms any gray-level or color image to a binary image using one of the selected adaptive thresholding algorithms.

Inputs🔗

  • image: Image to be thresholded. Color images will be converted to gray scale before applying the threshold.

  • windowSize: Size of the local window for adaptive threshold calculation.

  • absoluteLevel: Absolute threshold. The effect of this value depends on algorithm.

  • relativeLevel: Relative threshold. The effect of this value depends on algorithm.

  • algorithm: Adaptive thresholding algorithm.

  • invert: If true, inverts the result so that all foreground pixels become background and vice versa.

Outputs🔗

  • image: Binary image

enum Algorithm🔗

Thresholding algorithms.

Values:

enumerator RelativeToMean🔗

Local threshold is calculated by multiplying the mean gray level around a pixel by relativeLevel and adding absoluteThreshold to the result.

enumerator RelativeToMeanAndStd🔗

Local threshold is calculated by adding relativeThreshold times the standard deviation of the local gray levels to the mean gray level.

absoluteLevel will be added to the result.

enumerator WeightedMeanAndVariance🔗

Local threshold t is calculated as \( t = \mu (1 + r (\sigma/\sigma_{\mathrm max} - 1)) + a \), where r stands for relativeThreshold, a for absoluteThreshold, and \( \sigma_{\mathrm max} \) for the maximum possible standard deviation, which is assumed to be 128.

In document image binarization, a good value for relativeThreshold is 0.34, whereas absoluteThreshold is typically zero.