Image Thresholding Techniques in Computer Vision - GeeksforGeeks (2024)

Last Updated : 13 Jun, 2024

Improve

Image thresholding is a technique in computer vision that converts a grayscale image into a binary image by setting each pixel to either black or white based on a specific threshold value. The article provides a comprehensive overview of various image thresholding techniques used in computer vision, detailing their processes, pros, cons, and applications.

Table of Content

  • What is Image Thresholding?
  • Thresholding Techniques in Computer Vision
    • 1. Simple Thresholding
    • 2. Adaptive Thresholding
    • 3. Otsu’s Thresholding
    • 4. Multilevel Thresholding
    • 5. Color Thresholding
    • 6. Local Thresholding
    • 7. Global Thresholding
    • 8. Iterative Thresholding
  • Applications of Thresholding
  • Conclusion

What is Image Thresholding?

Image thresholding works on grayscale images, where each pixel has an intensity value between 0 (black) and 255 (white). The thresholding process involves converting this grayscale image into a binary image, where pixels are classified as either foreground (object of interest) or background based on their intensity values and a predetermined threshold. Pixels with intensities above the threshold are assigned to the foreground, while those below are assigned to the background.

Key Points:

  • Process: Compare each pixel’s intensity to a threshold value.
  • Result: Pixels above the threshold are set to white (255), and those below are set to black (0).
  • Purpose: Simplifies the image, making it easier to identify and analyze regions of interest.

Thresholding Techniques in Computer Vision

1. Simple Thresholding

Simple thresholding uses a single threshold value to classify pixel intensities. If a pixel’s intensity is greater than the threshold, it is set to 255 (white); otherwise, it is set to 0 (black).

[Tex]\begin{equation}T(x, y) =\begin{cases}0 & \text{if } I(x, y) \leq T \\255 & \text{if } I(x, y) > T\end{cases}\end{equation}[/Tex]

In this formula:

  • I(x,y) is the intensity of the pixel at coordinates (x, y).
  • T is the threshold value.
  • If the pixel intensity I(x,y) is less than or equal to the threshold T, the output pixel value is set to 0 (black).
  • If the pixel intensity I(x,y) is greater than the threshold T, the output pixel value is set to 255 (white).

Pros of Simple Thresholding

  • Simple and easy to implement.
  • Computationally efficient.

Cons of Simple Thresholding

  • Ineffective for images with varying lighting conditions.
  • Requires manual selection of the threshold value.

2. Adaptive Thresholding

Adaptive thresholding is used for images with non-uniform illumination. Instead of a single global threshold value, it calculates the threshold for small regions of the image, which allows for better handling of varying lighting conditions.

Types of Adaptive Thresholding

  • Mean Thresholding: The threshold value is the mean of the neighborhood area.
    • [Tex]T(x, y) = \sum_{(i, j) \in \mathcal{N}} f(i, j)[/Tex]
    • here,
      • N is the neighborhood of (x,y)
      • |N| is the number of pixels in the neighborhood
  • Gaussian Thresholding: The threshold value is a weighted sum (Gaussian window) of the neighborhood area.
    • [Tex]T(x,y)=\sum_{(i,j)\in \mathcal{N}}w(i,j)I(i,j)[/Tex]
    • here,
      • w(i,j) are the weights given by the Gaussian window

Pros of Adaptive Thresholding

  • Handles varying illumination well.
  • More accurate for complex images.

Cons of Adaptive Thresholding

  • More computationally intensive.
  • Requires careful selection of neighborhood size and method parameters.

3. Otsu’s Thresholding

Otsu’s method is an automatic thresholding technique that calculates the optimal threshold value by minimizing the intra-class variance (the variance within the foreground and background classes).

Steps to perform Otsu’s Thresholding

  1. Compute the histogram and probabilities of each intensity level.
  2. Compute the cumulative sums, means, and variances for all threshold values.
  3. Select the threshold that minimizes the within-class variance.
    • [Tex]\sigma_{b}^{2}(T)=\omega_{1}(T)\omega_{2}(T)(\mu_{1}(T)-\mu_{2}(T))^{2}[/Tex]
    • here,
      • where ω1 and ω2​ are the probabilities of the two classes separated by a threshold T, and μ1 and μ2​ are the means of these classes.

Pros of Otsu’s Thresholding

  • Automatic selection of the threshold value.
  • Effective for bimodal histograms.

Cons of Otsu’s Thresholding

  • Assumes a bimodal histogram, which may not be suitable for all images.
  • Computationally more intensive than simple thresholding.

4. Multilevel Thresholding

Multilevel thresholding extends simple thresholding by using multiple threshold values to segment the image into more than two regions. This is useful for images with complex structures and varying intensities.

Approaches of Multilevel Thresholding

  • Otsu’s Method Extension: Extending Otsu’s method to multiple levels.
  • Optimization Techniques: Using optimization algorithms to determine multiple thresholds.

Pros of Multilevel Thresholding

  • Can segment images into multiple regions.
  • Useful for images with complex intensity distributions.

Cons of Multilevel Thresholding

  • More computationally intensive.
  • Requires careful selection of the number of thresholds.

5. Color Thresholding

In color images, thresholding can be applied to each color channel (e.g., RGB, HSV) separately. This method leverages color information to segment objects.

Approaches of Color Thresholding

  • Manual Thresholding: Setting thresholds for each color channel manually.
  • Automatic Thresholding: Using methods like Otsu’s method for each channel.

Pros of Color Thresholding

  • Effective for segmenting objects based on color.
  • Can handle images with rich color information.

Cons of Color Thresholding

  • More complex than grayscale thresholding.
  • Requires careful selection of thresholds for each channel.

6. Local Thresholding

Local thresholding calculates a different threshold for each pixel based on its local neighborhood. This method is effective for images with non-uniform illumination or varying textures.

Techniques of Local Thresholding

1. Niblack’s Method

  • The threshold is calculated as the mean of the local neighborhood minus a constant times the standard deviation.
  • [Tex]T(x,y) = \mu(x,y) + k\sigma(x,y)[/Tex]
  • Here,
    • μ(x,y) is the mean and σ(x,y) is the standard deviation of the local neighborhood
    • k is a constant.

2. Sauvola’s Method

  • An improvement over Niblack’s method that adjusts the constant factor dynamically based on the mean and standard deviation.
  • [Tex]T(x,y) = \mu(x,y)[1 + k(\frac{\sigma(x,y)}{R} -1)][/Tex]
  • Here,
    • R is the dynamic range of the standard deviation
    • k is a constant

Pros of Local Thresholding

  • Handles non-uniform illumination well.
  • More accurate for textured images.

Cons of Local Thresholding

  • Computationally intensive.
  • Sensitive to parameter selection.

7. Global Thresholding

Global thresholding uses a single threshold value for the entire image. This technique is suitable for images with uniform lighting and clear contrast between the foreground and background.

Pros of Global Thresholding

  • Simple and easy to implement.
  • Computationally efficient.

Cons of Global Thresholding

  • Not suitable for images with varying illumination.
  • Requires manual selection of the threshold value

8. Iterative Thresholding

Iterative thresholding starts with an initial guess for the threshold value and iteratively refines it based on the mean intensity of the pixels above and below the threshold. The process continues until the threshold value converges.

Steps to perform Iterative Thresholding

  1. Choose an initial threshold value [Tex]T_o[/Tex]​.
  2. Segment the image into two classes [Tex]C_1[/Tex] and [Tex]C_2[/Tex]​ using [Tex]T_k[/Tex]​.
  3. Compute the mean intensities [Tex]\mu_1[/Tex] and [Tex]\mu_2[/Tex] of [Tex]C_1[/Tex] and [Tex]C_2[/Tex]​.
  4. Update the threshold value:
    • [Tex]T_{k+1} = \frac{\mu_1 + \mu_2}{2}[/Tex]
  5. Repeat steps 2-4 until [Tex]|T_{k+1}-T_k| < \epsilon[/Tex]

Pros of Iterative Thresholding

  • Provides an automatic way to determine the threshold.
  • Suitable for images with a clear distinction between foreground and background.

Cons of Iterative Thresholding

  • May require several iterations to converge.
  • Not effective for images with complex intensity distributions.

Applications of Thresholding

Thresholding techniques are used in various applications, including:

  1. Document Image Analysis: Thresholding is widely used to binarize text in scanned documents, making it easier for Optical Character Recognition (OCR) systems to process the text.
  2. Medical Imaging: In medical imaging, thresholding is used to segment anatomical structures in MRI or CT scans, aiding in diagnosis and treatment planning.
  3. Industrial Inspection: Thresholding is employed in industrial inspection systems to detect defects in manufactured products, ensuring quality control.
  4. Object Detection: In survillance footage or robotic vision systems, thresholding is used to identify and track objects, enhancing security and automation.

Conclusion

Thresholding is a crucial technique in computer vision for image segmentation. The choice of thresholding technique depends on the specific requirements of the application and the characteristics of the image. Simple thresholding and global thresholding are suitable for images with uniform lighting and clear contrast, while adaptive thresholding and local thresholding are more effective for images with varying illumination and textures. Techniques like Otsu’s method and iterative thresholding provide automatic ways to determine the optimal threshold value, making them useful in diverse applications. Understanding these techniques and their appropriate use cases is essential for effective image segmentation and analysis in computer vision.

By leveraging the strengths and understanding the limitations of each thresholding technique, practitioners can choose the most suitable method for their specific needs, leading to more accurate and efficient image processing workflows.



D

deepakp7eq

Improve

Previous Article

OpenCV | Understanding Contrast in an Image

Next Article

How to Identify Misclassified Samples in RandomForest in R

Please Login to comment...

Image Thresholding Techniques in Computer Vision - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Kimberely Baumbach CPA

Last Updated:

Views: 6144

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kimberely Baumbach CPA

Birthday: 1996-01-14

Address: 8381 Boyce Course, Imeldachester, ND 74681

Phone: +3571286597580

Job: Product Banking Analyst

Hobby: Cosplaying, Inline skating, Amateur radio, Baton twirling, Mountaineering, Flying, Archery

Introduction: My name is Kimberely Baumbach CPA, I am a gorgeous, bright, charming, encouraging, zealous, lively, good person who loves writing and wants to share my knowledge and understanding with you.