MATLAB File Help: cv.threshold | Index |

cv.threshold

Applies a fixed-level threshold to each array element

```
dst = cv.threshold(src, thresh)
dst = cv.threshold(src, thresh, 'OptionName',optionValue, ...)
[dst, thresh] = cv.threshold(src, 'auto', ...)
```

**src**Input array (single-channel, 8-bit, 16-bit, or 32-bit floating point).**thresh**Threshold value. Scalar numeric value or one of the strings:**Otsu**use Otsu algorithm to choose the optimal threshold value**Triangle**use Triangle algorithm to choose the optimal threshold value

**dst**Output array of the same size and type as`src`

.**thresh**Threshold value used.

**MaxValue**Maximum value to use with the 'Binary' and 'BinaryInv' thresholding types. default 255**Type**Thresholding type, default 'Binary'. One of:**Binary**`dst(x,y) = (src(x,y) > thresh) ? maxVal : 0`

**BinaryInv**`dst(x,y) = (src(x,y) > thresh) ? 0 : maxVal`

**Trunc**`dst(x,y) = (src(x,y) > thresh) ? thresh : src(x,y)`

**ToZero**`dst(x,y) = (src(x,y) > thresh) ? src(x,y) : 0`

**ToZeroInv**`dst(x,y) = (src(x,y) > thresh) ? 0 : src(x,y)`

The function applies fixed-level thresholding to a single-channel array.
The function is typically used to get a bi-level (binary) image out of a
grayscale image (cv.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.

When `thresh`

is set 'Otsu' or 'Triangle', the function determines the
optimal threshold value using the Otsu's or Triangle algorithm. The function
returns the computed threshold value. Currently, the Otsu's and Triangle
methods are implemented only for 8-bit images.