Histogram thresholding#
Binary thresholding#
A very simple method of segmentation consists in associating with each pixel of the image \(f\) a binary number which depends on the intensity of the pixels and on a threshold (French: seuil) \(T\):
This method is called “binarization” (French: binarisation). It gives a segmentation into two classes, depending on the intensity of the pixels of a grayscale image (Fig. 61).
As you can see, the segmentation depends on the value of \(T\). Therefore, the histogram is very useful to choose the threshold! As an example, Fig. 62 gives the histogram of the image, with the chosen thresholds.
It would be useful to have an automatic process to define the threshold, whatever the image to segment. Otsu’s method is the most famous automatic method for histogram thresholding.
Otsu’s method#
Binarization divides the histogram of the images in two groups, namely class 0 and class 1, as illustrated Fig. 63.
Each group has a number of pixel \(w_i(T)\) with mean \(\mu_i(T)\) and variance \(\sigma_i^2(T)\), where \(i\) is the group index (0 or 1). Otsu’s method [Otsu 1979] computes the threshold \(T\) which minimizes the intra-class variance \(\sigma_w^2(T)\) (also known as the within-class variance), defined as the weighted mean of the variances of each class:
Considering the intensities to lie in \(\{0,\dots,L-1\}\) and \(h\) the histogram, the variables are defined as below.
\(\displaystyle w_0(T) = \sum_{i = 0}^{T} h(i)\)
\(\displaystyle \mu_0(T) = \frac{1}{w_0(T)} \sum_{i = 0}^{T} i h(i)\)
\(\displaystyle \sigma^2_0(T) = \frac{1}{w_0(T)} \sum_{i = 0}^{T}(i-\mu_0(T))^2 h(i)\)
\(\displaystyle w_1(T) = \sum_{i = T+1}^{L-1} h(i)\)
\(\displaystyle \mu_1(T) = \frac{1}{w_1(T)} \sum_{i = T+1}^{L-1} i h(i)\)
\(\displaystyle \sigma^2_1(T) = \frac{1}{w_1(T)} \sum_{i = T+1}^{L-1}(i-\mu_1(T))^2 h(i)\)
The algorithm to determine the value of \(T\) that minimize \(\sigma_w^2(T)\) is simple: the intra-class variance \(\sigma_w^2(T)\) is calculated for all the thresholds \(T=\{0,\dots,L-1\}\), and the one that gives the lowest value for \(\sigma_w^2(T)\) is returned.
An example of Otsu’s thresholding is given Fig. 64.
Multiple thresholds#
An image can be segmented in more than two classes by defining or computing several thresholds (see Fig. 65). In particular, Otsu’s method can be extended to several thresholds, but the computational complexity (hence the computation time) increases greatly with the number of classes!