Implementation of Otsu's Method for automatic optimal threshold determination in image binarization. This statistical approach separates foreground and background by maximizing between-class variance, eliminating manual threshold tuning.
- Load image using OpenCV
- Accepts both grayscale and color images (converts color to grayscale)
- Fallback dummy image if input not found
- 256 bins (0-255 intensity levels)
- Normalized to probability distribution
For each threshold
- Split into two classes:
-
$C_1$ : pixels$\leq t$ -
$C_2$ : pixels$> t$
-
- Calculate class probabilities:
- Compute class means:
- Optimal threshold maximizes
$\sigma_b^2$
- Pixels
$> t \rightarrow 255$ (white) - Pixels
$\leq t \rightarrow 0$ (black)
- Original image
- Histogram with threshold line
- Binarized output
- Composite output showing original, histogram, and binarized result
- Threshold analysis and binarization output


