Otsu’s Thresholding Method
Otsu’s method is a technique of performing global thresholding on a digital image. It is optimum in the sense that it maximizes the between-class variance. The basic crux of the method is that well-thresholded classes of pixels must be distinct with respect to the intensity levels of their pixels and conversely, a threshold that gives the best separation between two different classes of pixels in terms of their intensity levels would be the optimum or the best threshold.
1. Let {0, 1, 2, 3,… , L-1} denote the L distinct intensity levels of the pixels in an M x N image.
2. Let ni denote the number of pixels with intensity level i. Total number of pixels in the image M_N = n_o + n_1 + …. + n_{L-1}.
3. The normalized histogram of the image will have components as probabilities of occurrence of an intensity level i as:
4. Clearly, we must have:
5. Let us pick a threshold T = k, where 0 < k < L-1. Using this threshold T, we segment the image into two separate classes C1 and C2.
- C1 consists of all pixels with intensity values in the range [0, k].
- C2 consists of pixels with intensity values in the range [k+1, L-1].
6. The probability that a pixel belongs to the class C1 P1(k) is given by:
If we have k = 0, the probability of class C1 having any pixel is basically zero.
7. Similarly, the probability of class C2 is:
8. Now, the mean intensity level of the pixels belonging to class C1 is:
Here, P(i|C1) is the probability of occurrence of intensity value i given that it is class C1.
9. Using Baye’s theorem in the above simplification we get:
Here, P(C1|i) is the probability of class C1 given that it is of intensity level i. This is obviously 1, as we are dealing with intensity values from class C1 only.
- P(i) is the probability of the ith intensity value which is pi
- P(C1) is the probability of class C1, which is, as computed above, equal to P1(k).
10. Similarity, by carrying over the same arguments for class C2, the mean intensity level of pixels of class C2 is:
11. The cumulative mean, that is, the average intensity, upto level k is defined as:
12. The average intensity (global mean) of the entire image is just summing over all the levels from 0 to L-1, that is:
13. From these definitions, we can easily see that: and
14. Now, we have the global variance as and the between-class variance is defined as:
15. This can also be written as:
16. Next, we define a figure of merit:
17. According to Otsu, the optimum threshold k=k’ is the one that maximizes
18. If the maximum exists for more than one value of k, then it is customary to take the average of the different maxima values, and assign it to k’. Once we have k’, we can directly segment the image f(x,y) as follows: g(x,y) = 1 if f(x,y)>k’ and g(x,y) = 0 if f(x,y)≤k’
Optimum Global Thresholding Using Otsu’s Method
Image thresholding is one of the segmentation techniques, that segments or divided the image into two or more different parts based on pixel intensities. There are many different algorithms for carrying out thresholding and here we are going to see one of the most efficient and optimum techniques called Otsu’s method.