Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

otsuthresh

Global histogram threshold using Otsu's method

Syntax

T = otsuthresh(counts)
[T,EM] = otsuthresh(counts)

Description

example

T = otsuthresh(counts) computes a global threshold T from histogram counts, counts, using Otsu's method [1]. T is a normalized intensity value that lies in the range [0, 1] that can be used with imbinarize to convert an intensity image to a binary image. Otsu's method chooses a threshold that minimizes the intraclass variance of the thresholded black and white pixels.

[T,EM] = otsuthresh(counts) returns the effectiveness metric, EM, which indicates the effectiveness of the thresholding. EM is in the range [0, 1].

Examples

collapse all

Read image into the workspace.

I = imread('coins.png');

Calculate a 16-bin histogram for the image.

[counts,x] = imhist(I,16);
stem(x,counts)

Compute a global threshold using the histogram counts.

T = otsuthresh(counts);

Create a binary image using the computed threshold and display the image.

BW = imbinarize(I,T);
figure
imshow(BW)

Input Arguments

collapse all

Histogram counts, specified as a real, nonsparse numeric vector of nonnegative values.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Global threshold value, returned as a numeric scalar of class double in the range [0, 1].

Effectiveness metric, returned as a numeric scalar of class double in the range [0, 1]. The lower bound is attainable only by histogram counts with all data in a single non-zero bin. The upper bound is attainable only by histogram counts with two non-zero bins.

References

[1] Otsu, N., "A Threshold Selection Method from Gray-Level Histograms," IEEE Transactions on Systems, Man, and Cybernetics, Vol. 9, No. 1, 1979, pp. 62-66.

Extended Capabilities

Introduced in R2016a

Was this topic helpful?