Skip to content

adaptiveThreshold

Image processingfunctionOpenCV 5.0.0
import { adaptiveThreshold } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Applies an adaptive threshold to an array.

The function transforms a grayscale image to a binary image according to the formulae:

  • THRESH_BINARY
dst(x,y) =  \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}
  • THRESH_BINARY_INV
dst(x,y) =  \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}

where T(x,y) is a threshold calculated individually for each pixel (see adaptiveMethod parameter).

The function can process the image in-place.

See: threshold, blur, GaussianBlur

adaptiveThreshold(src: Mat, dst: Mat, maxValue: number, adaptiveMethod: number, thresholdType: number, blockSize: number, C: number): void;
src

Source 8-bit single-channel image.

dst

Output destination, filled by the native operation. Destination image of the same size and the same type as src.

maxValue

Non-zero value assigned to the pixels for which the condition is satisfied

adaptiveMethod

Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes. The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries.

thresholdType

Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV, see #ThresholdTypes.

blockSize

Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.

C

Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.