Total Pageviews

Friday, September 25, 2026

๐Ÿ”„ Iterative Thresholding

๐Ÿ”„ Iterative Thresholding

B.Sc. Computer Science Honours | Digital Image Processing & Image Segmentation

๐Ÿ“˜ 1. Introduction

Iterative Thresholding, also called the Iterative Selection Method, is an image segmentation technique used to automatically determine a suitable threshold value from the intensity distribution of an image.

Instead of choosing the threshold manually, the algorithm starts with an initial estimate and repeatedly improves the threshold until the value becomes stable.

Core idea: Divide the image into two groups using an initial threshold, calculate the mean intensity of both groups, and use those means to calculate a new threshold.
Grayscale
Image
→
Divide into
Two Groups
→
Calculate
Means
→
New
Threshold
↻
Stable
Threshold

⚙️ 2. Basic Principle

Let the grayscale image contain pixel intensities represented by f(x,y).

Choose an initial threshold T. The pixels are divided into two groups:

G₁ = {f(x,y) > T}
G₂ = {f(x,y) ≤ T}

Calculate the mean intensity of each group:

ฮผ₁ = Mean(G₁)      ฮผ₂ = Mean(G₂)

Then calculate a new threshold:

Tnew = (ฮผ₁ + ฮผ₂) / 2

The process continues until the threshold becomes stable.

๐Ÿง  3. Iterative Thresholding Algorithm

Step 1: Convert the image into a grayscale image.
Step 2: Select an initial threshold T.
Step 3: Divide the pixels into two groups G₁ and G₂.
Step 4: Calculate the mean intensity ฮผ₁ of G₁.
Step 5: Calculate the mean intensity ฮผ₂ of G₂.
Step 6: Calculate the new threshold: Tnew = (ฮผ₁ + ฮผ₂) / 2.
Step 7: Compare the new threshold with the previous threshold.
Step 8: If the difference is sufficiently small, stop. Otherwise repeat the process.

๐Ÿ” 4. Complete Flow of Iterative Thresholding

Initial
T
→
G₁ & G₂
→
ฮผ₁ & ฮผ₂
→
Tnew
→
Compare
If the threshold has not converged: repeat the process. If it has converged: produce the segmented image.

๐Ÿ”ข 5. Numerical Example

Consider the following simplified set of grayscale pixel values:

20, 30, 40, 50, 60, 150, 160, 170, 180, 190

Assume the initial threshold is:

T₀ = 100

Iteration 1

Using T = 100:

Group Pixel Values Mean
G₁ > 100 150, 160, 170, 180, 190 170
G₂ ≤ 100 20, 30, 40, 50, 60 40

New threshold:

T₁ = (170 + 40) / 2 = 105

Iteration 2

Using T = 105, the groups remain unchanged.

ฮผ₁ = 170      ฮผ₂ = 40
T₂ = (170 + 40) / 2 = 105
Since: T₂ = T₁ = 105, the threshold has converged.
Final Threshold = 105

๐ŸŽฏ 6. Convergence Condition

The algorithm stops when the difference between consecutive threshold values becomes sufficiently small.

|Tnew − Told| < ฮต

Here, ฮต is a small tolerance value.

In a simple implementation, the algorithm can also stop when Tnew = Told.

๐Ÿ“ 7. Mathematical Formulation

Let the image contain N pixels and let the threshold at iteration k be Tk.

The two groups are:

G₁(Tโ‚–) = {f(x,y) | f(x,y) > Tโ‚–}
G₂(Tโ‚–) = {f(x,y) | f(x,y) ≤ Tโ‚–}

The group means are:

ฮผ₁(Tโ‚–) = Mean[G₁(Tโ‚–)]
ฮผ₂(Tโ‚–) = Mean[G₂(Tโ‚–)]

Then:

Tโ‚–₊₁ = [ฮผ₁(Tโ‚–) + ฮผ₂(Tโ‚–)] / 2

๐Ÿงช 8. Interactive Iterative Thresholding Calculator

Enter pixel values and click Calculate Iterations.

๐Ÿงฉ 9. 8×8 Image Matrix Demonstration

The following interactive matrix represents a simplified grayscale image. Iterative thresholding will automatically calculate a threshold from the matrix.

Generate a matrix and run the algorithm.

๐Ÿ 10. Beginner Python Implementation

The following Python program implements iterative thresholding without using a built-in automatic thresholding function.

import cv2 import numpy as np # Read image image = cv2.imread("input.jpg") # Convert to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Initial threshold T = 128 while True: # Group 1: pixels greater than threshold G1 = gray[gray > T] # Group 2: pixels less than or equal to threshold G2 = gray[gray <= T] # Calculate means if len(G1) == 0 or len(G2) == 0: break mean1 = np.mean(G1) mean2 = np.mean(G2) # Calculate new threshold new_T = (mean1 + mean2) / 2 print("Old T:", T) print("Mean G1:", mean1) print("Mean G2:", mean2) print("New T:", new_T) print("----------------") # Check convergence if abs(new_T - T) < 0.5: T = new_T break T = new_T # Convert threshold to integer T = int(round(T)) print("Final Threshold:", T) # Create binary image _, binary = cv2.threshold( gray, T, 255, cv2.THRESH_BINARY ) cv2.imshow("Original", image) cv2.imshow("Iterative Threshold", binary) cv2.waitKey(0) cv2.destroyAllWindows()

๐Ÿ 11. Python Code Explanation

cv2.imread(): Reads the input image.
cv2.cvtColor(): Converts the image into grayscale.
G1: Contains pixels greater than the current threshold.
G2: Contains pixels less than or equal to the current threshold.
np.mean(): Calculates the average intensity of each group.
new_T: New threshold obtained from the two group means.
cv2.threshold(): Produces the final binary image.

๐Ÿ“Š 12. Example Iteration Table

Iteration Old T ฮผ₁ ฮผ₂ New T
1 100 170 40 105
2 105 170 40 105
The algorithm stops because the threshold has become stable.

๐Ÿ“Š 13. Global vs Iterative Thresholding

Feature Global Thresholding Iterative Thresholding
Threshold Usually manually selected Calculated iteratively
Process Single threshold operation Repeated refinement
Automatic Selection Not necessarily Yes, from image statistics
Computation Low Higher than one-pass thresholding
Result Binary segmentation Binary segmentation using converged T

๐Ÿ“Š 14. Iterative Thresholding vs Otsu's Method

Feature Iterative Thresholding Otsu's Method
Basic Idea Repeatedly updates T using group means Selects T using a histogram-based class-separation criterion
Starting Value Usually requires an initial T Evaluates candidate thresholds
Iterations Yes Not iterative in the same sense
Statistics Two class means Class probabilities and variances
Automatic Yes Yes

๐ŸŒ 15. Applications

๐Ÿ“„ Document Processing

Separating text and background in scanned documents.

๐Ÿ”ข OCR

Preparing characters for optical character recognition.

๐Ÿงฌ Medical Image Analysis

Separating regions of interest based on intensity.

๐Ÿญ Industrial Inspection

Separating objects or defects from backgrounds.

๐Ÿ›ฐ️ Remote Sensing

Intensity-based separation of image regions.

๐Ÿ”ฌ Scientific Images

Segmenting objects with distinguishable intensity ranges.

✅ 16. Advantages

1. Automatically estimates a threshold from image statistics.
2. Simple mathematical concept.
3. Does not require testing every possible threshold as its basic operation.
4. Easy to implement using NumPy and OpenCV.
5. Useful when foreground and background have reasonably distinct intensity distributions.

⚠️ 17. Limitations

1. The method depends on the initial threshold and image intensity distribution.
2. It may perform poorly when foreground and background intensities overlap strongly.
3. Uneven illumination can reduce segmentation quality.
4. Noise can influence the calculated group means.
5. It is fundamentally a two-class thresholding approach in its basic form.

⏱️ 18. Computational Consideration

If the image contains N pixels and the algorithm performs K iterations, a straightforward implementation requires approximately:

O(N × K)

In practice, the number of iterations is usually relatively small for many simple images, but it depends on the image distribution, initial threshold and stopping condition.

๐Ÿ“ 19. Algorithm in Short

Choose
T₀
→
Create
G₁,G₂
→
Find
ฮผ₁,ฮผ₂
→
Tnew = (ฮผ₁+ฮผ₂)/2
→
Converged?
No → Repeat      Yes → Segment Image

๐ŸŽ“ 20. Important Examination Points

1. Iterative thresholding automatically estimates a threshold from image intensity statistics.
2. The image is divided into two groups using the current threshold.
3. The means of the two groups are calculated.
4. The new threshold is: Tnew = (ฮผ₁ + ฮผ₂) / 2.
5. The process continues until the threshold converges.
6. It is useful for image segmentation when foreground and background have reasonably different intensity distributions.

๐Ÿ“Œ 21. Quick Revision Table

Concept Key Point
Initial Threshold Starting estimate of T.
G₁ Pixels greater than T.
G₂ Pixels less than or equal to T.
ฮผ₁ Mean intensity of G₁.
ฮผ₂ Mean intensity of G₂.
New Threshold Tnew = (ฮผ₁ + ฮผ₂) / 2.
Stopping Condition |Tnew − Told| < ฮต.
Final Result Thresholded / segmented image.

No comments:

Post a Comment