Skip to content

threshold

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

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

imgproc_motion

Applies a fixed-level threshold to each array element.

The function applies fixed-level thresholding to a multiple-channel array. The function is typically used to get a bi-level (binary) image out of a grayscale image ( #compare could be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. There are several types of thresholding supported by the function. They are determined by type parameter.

Also, the special values #THRESH_OTSU or #THRESH_TRIANGLE may be combined with one of the above values. In these cases, the function determines the optimal threshold value using the Otsu's or Triangle algorithm and uses it instead of the specified thresh.

Note: Currently, the Otsu's method is implemented only for CV_8UC1 and CV_16UC1 images, and the Triangle's method is implemented only for CV_8UC1 images.

See: thresholdWithMask, adaptiveThreshold, findContours, compare, min, max

threshold(src: Mat, dst: Mat, thresh: number, maxval: number, type_: number): number;
src

input array (multiple-channel, CV_8U, CV_16S, CV_16U, CV_32F or CV_64F).

dst

Output destination, filled by the native operation. output array of the same size and type and the same number of channels as src.

thresh

threshold value.

maxval

maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding types.

type_

thresholding type (see #ThresholdTypes).

Returns

the computed threshold value if Otsu's or Triangle methods used.

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.