otsuthresh() - Image Processing
T = otsuthresh(counts) computes
a global threshold T from histogram counts, counts,
using Otsu's method. 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].Code Generation support:
Yes. MATLAB Function Block support:
Yes.
Syntax
T = otsuthresh(counts) example[T EM] =
otsuthresh(counts)
Example
Compute Threshold from Image Histogram and Binarize ImageOpen This Example
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)
Output / Return Value
Limitations
Alternatives / See Also
Reference