๐ Thresholding in Digital Image Processing
B.Sc. Computer Science Honours | Image Segmentation
๐ 1. Introduction
Thresholding is one of the simplest and most important techniques used in Digital Image Processing for separating an object from its background.
The basic idea is to compare the intensity value of each pixel with a selected threshold value T.
Image
T
Comparison
Image
⚙️ 2. Basic Principle
Let the grayscale intensity of a pixel be represented by f(x,y) and let T be the threshold.
0, if f(x,y) < T }
Here:
- f(x,y) = original grayscale pixel value
- T = threshold value
- g(x,y) = thresholded output
- 1 = foreground/object
- 0 = background
๐ข 3. Numerical Example
Consider the following grayscale pixel values:
Suppose the threshold is:
| Pixel Value | Comparison | Output |
|---|---|---|
| 20 | 20 < 128 | 0 |
| 60 | 60 < 128 | 0 |
| 100 | 100 < 128 | 0 |
| 140 | 140 ≥ 128 | 1 |
| 180 | 180 ≥ 128 | 1 |
| 220 | 220 ≥ 128 | 1 |
๐ 4. Types of Thresholding
1️⃣ Global Thresholding
Uses one threshold value for the entire image.
2️⃣ Local Thresholding
Uses threshold values that can vary across different regions of an image.
3️⃣ Adaptive Thresholding
Automatically calculates a threshold for local neighborhoods.
4️⃣ Otsu's Thresholding
Automatically selects a global threshold by maximizing the separation between two intensity classes.
๐ 5. Global Thresholding
In global thresholding, one threshold value is applied throughout the complete image.
Example:
๐ 6. Local Thresholding
In local thresholding, different regions of an image can use different threshold values.
Regions
Local T
Image
Local thresholding is useful when illumination is not uniform across the image.
๐ง 7. Adaptive Thresholding
Adaptive thresholding calculates the threshold based on the local neighborhood of each pixel.
Two commonly used approaches are:
Mean Adaptive Thresholding
Threshold is calculated using the mean of neighboring pixels.
Gaussian Adaptive Thresholding
Uses a weighted average where nearby pixels receive greater importance.
๐ 8. Otsu's Thresholding
Otsu's method is an automatic threshold-selection technique commonly used for separating an image into two classes.
It searches for a threshold that gives strong separation between the foreground and background classes.
Basic Idea
๐ 9. Histogram and Thresholding
A grayscale histogram represents the frequency of different intensity levels in an image.
Image
⚫⚪ 10. Binary Image Formation
Thresholding commonly converts a grayscale image into a binary image.
Black Pixel
Usually represented by intensity 0.
White Pixel
Usually represented by intensity 255.
๐งช 11. Interactive Thresholding Demonstration
๐งฉ 12. Thresholding on an Image Matrix
Consider an 8×8 grayscale image represented by pixel intensities. Thresholding converts every value into either foreground or background.
๐ 13. Beginner Python Code
The following example demonstrates simple global thresholding using OpenCV.
cv2.threshold() compares the grayscale pixel values with the threshold value. Pixels satisfying the threshold condition are assigned the maximum value, here 255, while the others become 0.
๐ 14. Beginner Python Code – Otsu Thresholding
๐ 15. Beginner Python Code – Adaptive Thresholding
๐ 16. Comparison of Thresholding Methods
| Method | Threshold | Suitable Situation |
|---|---|---|
| Global | One fixed T | Relatively uniform illumination |
| Local | Region dependent | Different image regions |
| Adaptive | Calculated locally | Uneven illumination |
| Otsu | Automatically selected | Images with two dominant intensity classes |
๐ง 17. Thresholding Algorithm
๐ 18. Applications
๐ Document Processing
Separating text from paper backgrounds.
๐ข OCR
Preparing scanned documents for Optical Character Recognition.
๐งฌ Medical Images
Isolating regions of interest in some medical images.
๐ญ Industrial Inspection
Detecting objects, defects or regions in manufactured products.
๐ฐ️ Satellite Images
Separating selected regions based on intensity information.
๐ฅ Object Segmentation
Separating foreground objects from suitable backgrounds.
✅ 19. Advantages
⚠️ 20. Limitations
๐ 21. Thresholding vs Edge Detection
| Feature | Thresholding | Edge Detection |
|---|---|---|
| Main Purpose | Separate regions/classes | Find intensity boundaries |
| Basic Principle | Compare pixel intensity with T | Measure intensity changes |
| Output | Usually binary regions | Usually edge map |
| Common Methods | Global, Otsu, Adaptive | Sobel, Prewitt, Canny |
๐ 22. Important Examination Points
๐ 23. Quick Revision Table
| Concept | Key Point |
|---|---|
| Threshold | Value used to separate intensity classes. |
| Binary Image | Image containing two main intensity levels. |
| Global Threshold | One threshold for the complete image. |
| Local Threshold | Threshold depends on an image region. |
| Adaptive Threshold | Threshold calculated from local neighborhoods. |
| Otsu | Automatic threshold selection based on class separation. |
| Application | Segmentation, OCR, inspection and image analysis. |
No comments:
Post a Comment