1. Introduction

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 thresholdingIt 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 H(i) of an image I with an intensity level of i is defined by the following equation:

(1)   \begin{equation*} H(i) = \sum_{x=1}^{M}\sum_{y=1}^{N} [I(x,y) = i] \end{equation*}

Where M and N represent the width and height of the image, respectively, and [I(x,y) = i] is a function that returns one (1) if the pixel at position (x,y) has an intensity value of i, 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)   \begin{equation*} C(i) = \sum_{j=0}^{i} \frac{H(j)}{M \times N} \end{equation*}

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 \mu be an image’s mean grayscale intensity value. The mathematical formulation is as follows:

(3)   \begin{equation*} \mu = \frac{1}{M \times N} \sum_{x=1}^{M}\sum_{y=1}^{N} I(x,y) \end{equation*}

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 (P_0 and P_1).

To calculate the between-class variance for the threshold value T, we use the following formula:

(4)   \begin{equation*} \text{var}(T) = P_0(T) \cdot P_1(T) \cdot (m_0(T) - m_1(T))^2 \end{equation*}

Here, P_0(T) and P_1(T) represent the probabilities of the background and foreground regions, respectively. We also define m_0(T) and m_1(T) as the mean grayscale intensity values of the background and foreground regions, respectively.

So, m_0(T) and m_1(T) are formulated as follows:

(5)   \begin{equation*} \begin{aligned} P_0(T) &= C(T) \\ P_1(T) &= 1 - C(T) \end{aligned} \end{equation*}

Moreover, we can  calculate the mean grayscale intensity values m_0(T) and m_1(T) as follows:

(6)   \begin{equation*} m_0(T) = \frac{\sum_{i=0}^{T-1} i \cdot H(i)}{P_0(T) \cdot MN} \end{equation*}

(7)   \begin{equation*} m_1(T) = \frac{\sum_{i=T}^{255} i \cdot H(i)}{P_1(T) \cdot MN} \end{equation*}

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 T_{opt}, is then chosen by the threshold value that yields the maximum between-class variance. We can mathematically express this process as follows:

(8)   \begin{equation*} T_{opt} = {argmax}_{T} (var(T) )\end{equation*}

Here, var(T) represents the between-class variance for a given threshold value T, and \operatorname*{argmax}_{T} means that we choose the value of T that maximizes var(T).

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:

segmentation

3. Pseudocode

We present a pseudocode of Otsu’s segmentation next:

Rendered by QuickLaTeX.com

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

6. Conclusion

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.

Comments are closed on this article!