Function threshold

Source
pub fn threshold(
    src: &impl GMatTraitConst,
    thresh: &impl GScalarTraitConst,
    maxval: &impl GScalarTraitConst,
    typ: i32,
) -> Result<GMat>
Expand description

Applies a fixed-level threshold to each matrix element.

The function applies fixed-level thresholding to a single- or multiple-channel matrix. The function is typically used to get a bi-level (binary) image out of a grayscale image ( cmp functions 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 cv::THRESH_OTSU or cv::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 . The function returns the computed threshold value in addititon to thresholded matrix. The Otsu’s and Triangle methods are implemented only for 8-bit matrices.

Input image should be single channel only in case of cv::THRESH_OTSU or cv::THRESH_TRIANGLE flags. Output matrix must be of the same size and depth as src.

Note: Function textual ID is “org.opencv.core.matrixop.threshold”

§Parameters

  • src: input matrix ([CV_8UC1], [CV_8UC3], or [CV_32FC1]).
  • thresh: threshold value.
  • maxval: maximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding types.
  • type: thresholding type (see the cv::ThresholdTypes).

§See also

min, max, cmpGT, cmpLE, cmpGE, cmpLT