function threshold_(image, method = "binary", inverted = false, threshValue = 0.5) {
    const $image = (0, _tensorUtilEnv.convertToTensor)(image, "image", "threshold");
    /* 0.2989, 0.5870, 0.1140 are represent luma coefficients in CCIR601.
    Reference for converting between RGB and grayscale: https://en.wikipedia.org/wiki/Luma_%28video%29  */ const RED_INTENCITY_COEF = 0.2989;
    const GREEN_INTENCITY_COEF = 0.5870;
    const BLUE_INTENCITY_COEF = 0.1140;
    const totalPixelsInImage = $image.shape[0] * $image.shape[1];
    let $threshold = (0, _mul.mul)((0, _tensor1D.tensor1d)([
        threshValue
    ]), 255);
    let r, g, b, grayscale;
    _util.assert($image.rank === 3, ()=>"Error in threshold: image must be rank 3," + `but got rank ${$image.rank}.`);
    _util.assert($image.shape[2] === 3 || $image.shape[2] === 1, ()=>"Error in threshold: image color channel must be equal to 3 or 1" + `but got ${$image.shape[2]}.`);
    _util.assert($image.dtype === "int32" || $image.dtype === "float32", ()=>"Error in dtype: image dtype must be int32 or float32," + `but got dtype ${$image.dtype}.`);
    _util.assert(method === "otsu" || method === "binary", ()=>`Method must be binary or otsu, but was ${method}`);
    if ($image.shape[2] === 3) {
        [r, g, b] = (0, _split.split)($image, [
            1,
            1,
            1
        ], -1);
        const $r = (0, _mul.mul)(r, RED_INTENCITY_COEF);
        const $g = (0, _mul.mul)(g, GREEN_INTENCITY_COEF);
        const $b = (0, _mul.mul)(b, BLUE_INTENCITY_COEF);
        grayscale = (0, _add.add)((0, _add.add)($r, $g), $b);
    } else grayscale = image;
    if (method === "otsu") {
        const $histogram = (0, _bincount.bincount)((0, _cast.cast)((0, _round.round)(grayscale), "int32"), (0, _tensor.tensor)([]), 256);
        $threshold = otsu($histogram, totalPixelsInImage);
    }
    const invCondition = inverted ? (0, _lessEqual.lessEqual)(grayscale, $threshold) : (0, _greater.greater)(grayscale, $threshold);
    const result = (0, _cast.cast)((0, _mul.mul)(invCondition, 255), "int32");
    return result;
}
Performs image binarization with corresponding threshold
(depends on the method)value, which creates a binary image from a grayscale.
@param image 3d tensor of shape [imageHeight,imageWidth, depth],
where imageHeight and imageWidth must be positive.The image color
range should be [0, 255].
@param method Optional string from `'binary' | 'otsu'`
which specifies the method for thresholding. Defaults to 'binary'.
@param inverted Optional boolean whichspecifies
if colours should be inverted. Defaults to false.
@param threshValue Optional number which defines threshold value from 0 to 1.
Defaults to 0.5.
@return A 3d tensor of shape [imageHeight,imageWidth, depth], which
contains binarized image.