<< morphologyEx | Image filtering | Image operations >>

scicv >> Image filtering > threshold

# threshold

Converts an image to a binary image.

### Syntax

    img_out = threshold(img_in, threshold_value, max_value, thresholding_type)

### Parameters

img_in

  Input image (single channel) (Mat).

threshold_value

  Threshold value (double).

max_value

  Maximum value used with `THRESH_BINARY` and `THRESH_BINARY_INV` method. (double).

thresholding_type

  Thresholding type, see below (double).

img_out

  Output image (Mat).

### Description

`threshold` transforms a (usually grayscale) image into a a binary image, using a specified method:

- THRESH_BINARY
- THRESH_BINARY_INV
- THRESH_TRUNC
- THRESH_TOZERO
- THRESH_TOZERO_INV
- THRESH_OTSU

### Examples

    scicv_Init();

    img = imread(getSampleImage("puffin.png"), CV_LOAD_IMAGE_GRAYSCALE);

    subplot(1,2,1);
    matplot(img);

    [thresh, img_bw] = threshold(img, 125, 255, THRESH_BINARY);

    subplot(1,2,2);
    matplot(img_bw);

    delete_Mat(img);
    delete_Mat(img_bw);

Report an issue
<< morphologyEx | Image filtering | Image operations >>