Histogram thresholding

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:

g(m,n)={1iff(m,n)T,0iff(m,n)<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).

../_images/binarization.svg

Fig. 61 Example of binarization for two thresholds.#

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.

../_images/binarization-histogram.svg

Fig. 62 Histogram of Fig. 61 with the two 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.

../_images/otsu-histogram.svg

Fig. 63 An histogram and a threshold T.#

Each group has a number of pixel wi(T) with mean μi(T) and variance σi2(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 σw2(T) (also known as the within-class variance), defined as the weighted mean of the variances of each class:

σw2(T)=w0(T)σ02(T)+w1(T)σ12(T).

Considering the intensities to lie in {0,,L1} and h the histogram, the variables are defined as below.

Class 1

w0(T)=i=0Th(i)

μ0(T)=1w0(T)i=0Tih(i)

σ02(T)=1w0(T)i=0T(iμ0(T))2h(i)

Class 2

w1(T)=i=T+1L1h(i)

μ1(T)=1w1(T)i=T+1L1ih(i)

σ12(T)=1w1(T)i=T+1L1(iμ1(T))2h(i)

The algorithm to determine the value of T that minimize σw2(T) is simple: the intra-class variance σw2(T) is calculated for all the thresholds T={0,,L1}, and the one that gives the lowest value for σw2(T) is returned.

An example of Otsu’s thresholding is given Fig. 64.

../_images/otsu.svg

Fig. 64 Result of Otsu’s segmentation.#

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!

../_images/multiple-thresholds.svg

Fig. 65 Several thresholds are applied to an image to get several classes (shown in colors).#