# thresholdcv

Applies a threshold to each element of the given image, handle, resulting in a grayscale image, R, whose pixels represent the elements exceeding the threshold.

## Syntax

[computedthreshold, R] = thresholdcv(handle, threshold, max, type)

## Inputs

handle
Handle of an image.
Type: integer
threshold
Real vector of [width height] representing the dimensions of R.
Type: vector
fx
Threshold value.
Type: scalar
max
Maximum value to use with type value of 8 or 16.
Type: scalar
type
Threshold type. Valid values are:
0
R(x,y) = max if handle(x,y) > threshold and 0 otherwise.
1
R(x,y) = 0 if handle(x,y) > threshold and max otherwise.
2
R(x,y) = threshold if handle(x,y) > threshold and handle(x,y) otherwise.
3
R(x,y) = handle(x,y) if handle(x,y) > threshold and 0 otherwise.
4
R(x,y) = 0 if handle(x,y) > threshold and handle(x,y) otherwise.
8
Uses Otsu algorithm for optimal threshold.
16
Uses Triangle algorithm for optimal threshold.
Type: integer

## Outputs

computedthreshold
Computed threshold value.
Type: scalar
R
Handle of the resized image.
Type: integer

## Example

Apply a threshold to an image:
[computedthreshold, mask] = thresholdcv(handle, 10, 255, 0);
Apply a threshold to an image containing numbers written in grayscale equal to the number itself with threshold equals to zero and maximum value equals to 255 (white):
figure(1);
imshowcv(src);

thresh = 0;
maxValue = 255;

[computedthreshold, mask] = thresholdcv(src, thresh, maxValue, 0); %Binary threshold

figure(2);
Apply a threshold to the same image as described above containing numbers with threshold equals to 127, which removes all numbers less than or equal to 127:
figure(1);
imshowcv(src);

thresh = 127;
maxValue = 255;

[computedthreshold, mask] = thresholdcv(src, thresh, maxValue, 0); %Binary threshold

figure(2);
Apply a threshold as described in the previous example with a maximum value of 150, to set the value of the thresholded regions to 150:
figure(1);
imshowcv(src);

thresh = 127;
maxValue = 150;

[computedthreshold, mask] = thresholdcv(src, thresh, maxValue, 0); %Binary threshold

figure(2);
Apply a threshold to the same image as described above with threshold equals to zero and maximum value equals to 255 (white), but using the inverse binary thresholding:
figure(1);
imshowcv(src);

thresh = 0;
maxValue = 255;

[computedthreshold, mask] = thresholdcv(src, thresh, maxValue, 1); %Inverse binary threshold

figure(2);