Start » Filter Reference » OpenCV » Miscellaneous Image Transformations » cvAdaptiveThreshold

cvAdaptiveThreshold


Module: OpenCV

Applies an adaptive threshold to an image.

Name Type Range Description
Input value
inSrc Image UINT8, single-channel input image.
Input value
inMaxValue Real Non-zero value assigned to the pixels for which the condition is satisfied.
Input value
inAdaptiveMethod CvAdaptiveMethod Adaptive thresholding algorithm to use.
Input value
inThresholdType CvThresholdType Thresholding type.
Input value
inBlockSize Integer 3 - Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.
Input value
inC Real Constant subtracted from the mean or weighted mean
Output value
outDst Image Output image.

Description

The operation transforms each pixel value to the maximum or minimum level thus creating binary image. The result of the transformation depends on the relative pixel intensity:

  • Pixel values that are brighter than local average of the pixel neighbourhood are transformed to inMaxValue.
  • Other pixel values are transformed to 0.

Pixel neighbourhood used to compute the local average is a rectangle of dimensions (inBlockSize) x (inBlockSize) centered at the pixel being processed.

Local average is computed according to method specified in inAdaptiveMethod:

  • For the method ADAPTIVE_THRESH_MEAN, the threshold value is mean of pixels in neighbourhood minus inC.
  • For the method ADAPTIVE_THRESH_GAUSSIAN, the threshold value is a weighted sum of values in pixels in neighbourhood minus inC. The weights are computed using normal distribution with default sigma value for specified inBlockSize

Examples

cvAdaptiveThreshold performed on the sample image with inAdaptiveMethod = ADAPTIVE_THRESH_GAUSSIAN, inThresholdType = THRESH_BINARY, inBlockSize = 13, inC = -5.0.

Errors

This filter can throw an exception to report error. Read how to deal with errors in Error Handling.

List of possible exceptions:

Error type Description
DomainError Input image must be UINT8 single-channel in cvAdaptiveThreshold.

Complexity Level

This filter is available on Basic Complexity Level.