Compute global image threshold for histogram using Otsu’s method.
Given an image histogram hist finds the optimal threshold
value level for conversion to a binary image with
im2bw
.
The Otsu’s method chooses the threshold value that minimises the intraclass variance between two classes, the background and foreground. The method is described in Nobuyuki Otsu (1979). "A threshold selection method from gray-level histograms", IEEE Trans. Sys., Man., Cyber. 9 (1): 62-66.
The second output, sep represents the “goodness” (or separability) of the threshold at level. It is a value within the range [0 1], the lower bound (zero) being attainable by, and only by, histograms having a single constant grey level, and the upper bound being attainable by, and only by, two-valued pictures.
See also: graythresh, im2bw.
The following code
I = max (phantom (), 0); figure; imshow (I); title ("Original image"); h = imhist (I); t = otsuthresh (h); J = im2bw (I); figure; imshow (J); title_line = sprintf ("Black and white image after thresholding, t=%g", t*255); title (title_line);
Produces the following figures
Figure 1 | Figure 2 |
---|---|
The following code
warning ("off", "Octave:data-file-in-path", "local"); S = load ("penny.mat"); I = uint8 (S.P); figure; imshow (I); title ("Original penny image"); h = imhist (I); t = otsuthresh (h); J = im2bw (I); figure; imshow (J); title_line = sprintf ("Black and white penny image after thresholding, t=%g", t*255); title (title_line); I = 255 - I; figure; imshow(I); title ("Negative penny image"); h = imhist (I); t = otsuthresh (h); J = im2bw (I); figure; imshow (J); title_line = sprintf ("Black and white negative penny image after thresholding, t=%g", t*255); title (title_line);
Produces the following figures
Figure 1 | Figure 2 | Figure 3 | Figure 4 |
---|---|---|---|
Package: image