Image segmentation is an important step in most computer vision applications. Image segmentation involves dividing an image into multiple regions or segments based on some criteria. In particular, one of the most popular methods for image segmentation is Otsu’s method.
In this tutorial, we’ll cover the details of Otsu’s method, its advantages and limitations, and some applications.
2. Otsu’s Method: an Overview
Otsu’s method is a popular technique employed for image thresholding. It separates an image into two classes, foreground, and background, based on the grayscale intensity values of its pixels.
Furthermore, Otsu’s method uses the grayscale histogram of an image to detect an optimal threshold value that separates two regions with maximum inter-class variance.
In the following subsections, we will discuss the main steps of Otsu’s method in detail.
2.1. Compute the Grayscale Histogram (Step 1)
The grayscale histogram of an image shows the distribution of pixel intensity values in it. We can obtain such a histogram by counting the number of pixels at each intensity level.
Hence, the grayscale histogram of an image with an intensity level of is defined by the following equation:
Where and represent the width and height of the image, respectively, and is a function that returns one (1) if the pixel at position has an intensity value of , and zero (0) otherwise.
2.2. Compute the Cumulative Distribution Function (Step 2)
The Cumulative Distribution Function (CDF) represents the probability that a pixel in the image has a grayscale intensity value less than or equal to a particular level.
For computing CDF from a grayscale histogram, we sum the values of the histogram up to each intensity level. The mathematical formulation is as follows:
2.3. Compute the Mean Grayscale Intensity Value of the Image (Step 3)
The mean grayscale intensity value of the image is the process of averaging the grayscale intensity values of all the pixels in it. Additionally, Otsu’s method uses the mean grayscale value to compute the between-class variance.
So, let be an image’s mean grayscale intensity value. The mathematical formulation is as follows:
2.4. Compute the Between-Class Variance for Each Possible Threshold Value (Step 4)
The between-class variance measures the separation between the foreground and background regions. We can compute the between-class variance as the product of the square of the difference between the mean grayscale intensity values and the probabilities of the regions ( and ).
To calculate the between-class variance for the threshold value , we use the following formula:
Here, and represent the probabilities of the background and foreground regions, respectively. We also define and as the mean grayscale intensity values of the background and foreground regions, respectively.
So, and are formulated as follows:
Moreover, we can calculate the mean grayscale intensity values and as follows:
2.5. Find the Threshold Value That Maximizes the Between-Class Variance (Step 5)
To find the optimal threshold for image segmentation, we need to define the threshold value that maximizes the between-class variance.
Thus, we first compute the between-class variance for each possible threshold value. The optimal threshold value, denoted as , is then chosen by the threshold value that yields the maximum between-class variance. We can mathematically express this process as follows:
Here, represents the between-class variance for a given threshold value , and means that we choose the value of that maximizes .
Once we have determined the optimal threshold value, we can apply it to the grayscale image to obtain a binary image. In this binary image, the pixels with intensity values above the threshold are assigned to the foreground region. On the contrary, the pixels with intensity values below the threshold are assigned to the background region.
The figure next shows an original image and its Otsu’s segmented counterpart, highlighting the effectiveness of the segmentation technique in separating objects of interest from their background:
We present a pseudocode of Otsu’s segmentation next:
4. Advantages and Disadvantages of Otsu’s Method
Otsu’s method has many benefits, including its simplicity and speed. It does not require prior knowledge about the processed image and can automatically determine the optimal threshold value that separates its foreground and background regions. Additionally, it works well with bimodal histograms, which are common in many applications.
However, Otsu’s method has some limitations that should be taken into consideration:
- It may not perform well with images that have histograms with more than two peaks, as it can only determine one threshold value
- It assumes that the foreground and background regions have equal variances, which may not be true in some cases, leading to poor segmentation results
- It can produce inaccurate results for images with uneven lighting or illumination
- It is not robust to noise, which can lead to inaccurate thresholding results
Overall, Otsu’s method is useful for simple image thresholding tasks. However, its limitations should be considered when applying it to more complex images or in the presence of noise or uneven lighting.
5. Applications of Otsu’s Method
Otsu’s method is a widely applicable technique that finds its use in numerous applications in computer vision and image processing.
Some of the applications of Otsu’s method are as follows:
- Object Detection and Recognition: Otsu’s method can effectively segment images into foreground and background regions, which makes it useful for detecting and recognizing objects in images
- Medical Imaging: Otsu’s method is extensively used in medical imaging applications for segmenting images of organs and tissues. Since it can assist in identifying abnormalities or anomalies in the images and help in the diagnosis
- Document Analysis: Otsu’s method finds its application in segmenting handwritten or printed text in document images, which can aid in optical character recognition (OCR) and document analysis
- Quality Control and Inspection: Otsu’s method can be used in quality control and inspection applications to detect defects or anomalies in images of manufactured products
Otsu’s method uses the grayscale histogram of an image to find an optimal threshold value that separates the foreground and background regions with maximum inter-class variance. Moreover, Otsu’s method has numerous applications in computer vision and image processing and remains a popular choice for thresholding and segmentation tasks.
In conclusion, Otsu’s method is a simple yet effective thresholding technique for image segmentation tasks.