This method applies fixed-level thresholding to single-channel array. It is typically used
to get bi-level (binary) image out of grayscale image or for removing a noise (filtering out
pixels with too small or too large values).

About types of thresholding

THRESH_BINARY : dst(x,y) = src(x,y) > value ? max : 0

THRESH_BINARY_INV : dst(x,y) = src(x,y) > value ? 0 : max

THRESH_TRUNC : dst(x,y) = src(x,y) > value ? value : src(x,y)

THRESH_TOZERO : dst(x,y) = src(x,y) > value ? src(x,y) : 0

THRESH_TOZERO_INV : dst(x,y) = src(x,y) > value ? 0 : src(x,y)

THRESH_OTSU : Use Otsu algorithm to choose the optimal threshold value,
combine the flag with one of the above THRESH_* values

Syntax

threshold(value, max, type);threshold(value);

Parameters

value

float : threshold value

max

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