Otsu's Method
Introduction
Otsu's method is a thresholding technique used in image processing. Named after its inventor, Nobuyuki Otsu, it is a non-parametric method that automatically performs clustering-based image thresholding, or, the reduction of a gray-level image to a binary image. The algorithm assumes that the image contains two classes of pixels following a bi-modal histogram (foreground pixels and background pixels), it then calculates the optimum threshold separating the two classes so that their combined spread (intra-class variance) is minimal, or equivalently (because the sum of pairwise squared distances is constant), so that their inter-class variance is maximal.
Mathematical Description
Otsu's method is based on the principle of maximizing the inter-class variance between the black and white pixels in the binary image, or equivalently, minimizing the intra-class variance. The variance is a measure of the spread of a distribution, and the inter-class variance is the weighted sum of the variances of the two classes of pixels.
Let's denote the pixels at levels 0 through L-1 in an L-level grayscale image. The probability of occurrence of a pixel of level i in the image is:
p_i = n_i/N
where n_i is the number of pixels at level i and N is the total number of pixels in the image.
The weights ω_0 and ω_1 of the two classes are the probabilities of class occurrence:
ω_0 = ∑_(i=0)^(t-1) p_i and ω_1 = ∑_(i=t)^(L-1) p_i
The class means μ_0 and μ_1 can be expressed as:
μ_0 = ∑_(i=0)^(t-1) i*p_i / ω_0 and μ_1 = ∑_(i=t)^(L-1) i*p_i / ω_1
The variance σ^2 of the entire image is given by:
σ^2 = ∑_(i=0)^(L-1) (i - μ_T)^2 * p_i
where μ_T is the total mean level of the image, given by:
μ_T = ω_0 * μ_0 + ω_1 * μ_1
The inter-class variance σ_B^2 is then given by:
σ_B^2 = ω_0 * (μ_0 - μ_T)^2 + ω_1 * (μ_1 - μ_T)^2
Otsu's method involves finding the threshold t that maximizes the inter-class variance σ_B^2.
Algorithm
The algorithm for Otsu's method can be summarized as follows:
1. Compute the histogram and probabilities of each intensity level. 2. Set up initial ω_i(0) and μ_i(0). 3. Step through all possible thresholds t=1,…, maximum intensity. 4. Update ω_i and μ_i. 5. Compute σ_B^2. 6. Desired threshold corresponds to the maximum σ_B^2.
Applications
Otsu's method is widely used in image processing tasks, particularly for binarization of grayscale images. It has found applications in a variety of fields, including:
- Medical imaging: Otsu's method is often used in medical imaging to separate the interesting regions of an image from the background. For example, it can be used to isolate tumors in an MRI scan or cells in a microscopic image. - Document analysis: In document analysis and OCR (Optical Character Recognition), Otsu's method is used to separate the text (foreground) from the background. - Industrial inspection: In industrial inspection systems, Otsu's method can be used to detect defects or to separate objects of interest from the background. - Video surveillance: In video surveillance, Otsu's method can be used to separate moving objects from the static background.
Limitations
While Otsu's method is simple and effective in many cases, it has some limitations. It assumes that the image is composed of two classes of pixels (foreground and background), which may not always be the case. It also assumes that the grayscale histogram of the pixels of the image is bi-modal, which may not be true for all images. Furthermore, it does not take into account the spatial distribution of the pixels, which can lead to poor results if the object of interest is small compared to the size of the image.
See Also
- Image thresholding - Image processing - Histogram equalization - Image segmentation