1 Problem Setting and Intuition
1.1 Two-Class Image Segmentation
In grayscale image processing, a common task is to convert an image into two categories, often described as foreground and background. A threshold value separates pixel intensities into these two groups: pixels darker than the threshold belong to one class and pixels brighter than it belong to the other. The threshold selection problem is therefore the question of which intensity cut best reflects the intended segmentation.
1.2 Histogram-Based Thresholding
Otsu’s method addresses thresholding using the image’s intensity histogram. The histogram summarizes how frequently each grayscale level occurs (or, in continuous formulations, the probability density of intensities). Rather than requiring hand-chosen parameters, the method evaluates every plausible threshold and measures how well it partitions the histogram into two coherent groups.
1.3 Separation via Variance
The central intuition is that a good split should produce classes whose intensity values are internally consistent and clearly separated from each other. This idea is expressed using variance: if the two classes have distinct means and relatively tight spread, then the separation is strong. Otsu’s criterion formalizes this by focusing on the variance between the two classes, which increases when the split produces well-separated groups.
2 Mathematical Formulation
2.1 Class Definitions by Threshold
Assume a grayscale image with intensity levels indexed by \(i\). Choose a threshold \(t\). Pixels with intensities in \(\{0,\dots,t\}\) form class 0, and pixels with intensities in \(\{t+1,\dots,L-1\}\) form class 1, where \(L\) is the number of possible intensity levels (e.g., 256 for 8-bit images). This partition induces class statistics based directly on the histogram counts.
2.2 Class Probabilities
Let \(h(i)\) denote the histogram count at intensity \(i\). Define the total number of pixels \(N=\sum_{i=0}^{L-1} h(i)\). The class probabilities for threshold \(t\) are \[ \omega_0(t)=\sum_{i=0}^{t} \frac{h(i)}{N}, \quad \omega_1(t)=\sum_{i=t+1}^{L-1} \frac{h(i)}{N}. \] These quantities represent the fraction of pixels assigned to each class.
2.3 Class Means
The mean intensity of each class under threshold \(t\) is computed as \[ \mu_0(t)=\sum_{i=0}^{t} i \, \frac{h(i)}{N\,\omega_0(t)}, \quad \mu_1(t)=\sum_{i=t+1}^{L-1} i \, \frac{h(i)}{N\,\omega_1(t)}. \] A global mean \(\mu_T\) for the whole image is also defined: \[ \mu_T=\sum_{i=0}^{L-1} i \, \frac{h(i)}{N}. \]
2.4 Within-Class Variance
Otsu’s formulation can be expressed through within-class variance, which measures how dispersed intensities are around their respective class means. For threshold \(t\), \[ \sigma_w^2(t)=\omega_0(t)\sigma_0^2(t)+\omega_1(t)\sigma_1^2(t), \] where \(\sigma_k^2(t)\) is the variance within class \(k\). In practice, the algorithm avoids repeatedly recomputing full variances by using identities that relate this measure to between-class quantities.
2.5 Between-Class Variance
The between-class variance quantifies separation between the class means: \[ \sigma_b^2(t)=\omega_0(t)\,\big(\mu_0(t)-\mu_T\big)^2+\omega_1(t)\,\big(\mu_1(t)-\mu_T\big)^2. \] This value becomes larger when the means of the two classes differ substantially and both classes are represented by nontrivial proportions of the pixels.
3 Optimization Criterion
3.1 Maximizing Between-Class Variance
Otsu’s method selects the threshold \(t^*\) that maximizes the between-class variance: \[ t^*=\arg\max_t \sigma_b^2(t). \] Intuitively, the best threshold is the one that yields the strongest intensity separation between the two histogram partitions.
3.2 Equivalent Minimization of Within-Class Variance
For the two-class case, maximizing \(\sigma_b^2(t)\) is equivalent to minimizing the within-class variance \(\sigma_w^2(t)\). This equivalence arises because the total variance of the intensities can be decomposed into within-class and between-class components, with the total variance fixed for a given histogram.
3.3 Deriving the Objective from Variance Identities
Using the variance decomposition identity, \[ \sigma_T^2 = \sigma_w^2(t) + \sigma_b^2(t), \] and noting that \(\sigma_T^2\) depends only on the overall histogram (not on the threshold), the threshold that maximizes \(\sigma_b^2(t)\) automatically minimizes \(\sigma_w^2(t)\). This allows an efficient computation by focusing on the between-class term.
3.4 Choosing the Optimal Threshold
Operationally, the method evaluates \(\sigma_b^2(t)\) for each candidate threshold \(t\) and returns the intensity level associated with the maximum value. If multiple thresholds yield the same maximum (possible in quantized or sparse histograms), a consistent tie-breaking rule is typically applied, such as choosing the smallest \(t\) or the first maximum encountered.
4 Algorithm and Implementation Details
4.1 Building the Intensity Histogram
The first step is to compute the histogram of grayscale intensities. For an 8-bit image, histogram bins correspond to integer intensity levels 0 through 255. If the input image is stored with a different bit depth, values are either used directly or quantized into an appropriate number of bins.
4.2 Iterating Over Candidate Thresholds
A straightforward implementation loops over all thresholds \(t\) from the lowest intensity to the second-highest intensity (so that both classes can potentially be nonempty). For each \(t\), cumulative sums are used to compute \(\omega_0(t)\), \(\mu_0(t)\), \(\omega_1(t)\), and \(\mu_1(t)\) efficiently. The algorithm then computes \(\sigma_b^2(t)\) and keeps track of the maximum.
A common optimization is to precompute cumulative quantities (such as cumulative pixel counts and cumulative weighted intensities) so each threshold’s class statistics can be derived in constant time.
4.3 Handling Edge Cases (Empty Classes)
Certain thresholds may result in one class receiving no pixels, yielding \(\omega_0(t)=0\) or \(\omega_1(t)=0\). In such cases, class mean definitions become undefined. Implementations typically skip those thresholds or define the objective to be zero when a class is empty, ensuring that valid partitions dominate the maximization.
4.4 Numerical Considerations and Stability
Because probabilities and means may be derived from large pixel counts, numerical stability matters. Using floating-point arithmetic for cumulative sums and variance computations helps avoid overflow and preserves precision. Additionally, the objective can be sensitive to rounding when histograms are highly concentrated; using a stable formulation of \(\sigma_b^2(t)\) (in terms of cumulative means and probabilities) reduces cancellation errors.
5 Variants and Extensions
5.1 Multilevel (Multi-Class) Otsu Thresholding
The original Otsu criterion is designed for two classes. Multilevel variants extend the approach to split the histogram into more than two classes by selecting multiple thresholds. This typically involves dynamic programming or exhaustive search to maximize a generalized between-class variance measure across all classes.
5.2 Otsu on Normalized Histograms
In implementations, the histogram can be treated as counts \(h(i)\) or as normalized probabilities \(p(i)=h(i)/N\). The criterion is mathematically consistent under normalization, but using probabilities can simplify interpretation and reduce dependence on image size. In either case, the computations reduce to the same variance-based objective when carried out consistently.
5.3 Weighted / Modified Histograms
In some applications, histogram bins may be adjusted to reflect additional knowledge, such as sensor characteristics, known priors, or spatial importance of pixels. Weighted histogram variants modify bin contributions before applying the Otsu criterion, effectively biasing the selection toward thresholds that better match the weighted data distribution.
5.4 Practical Adaptations for Noisy Images
Noise can blur the histogram, reducing the clarity of the two dominant groups. Practical adaptations include smoothing the histogram, using larger bin widths, or applying Otsu’s method after denoising the image. Another approach is to constrain the search range for the threshold based on domain expectations, limiting the method’s sensitivity to spurious peaks.
6 Performance and Practical Use
6.1 When the Assumptions Hold
Otsu’s method performs best when the histogram is well modeled as a mixture of two relatively distinct intensity distributions. This often corresponds to scenes where foreground and background intensities are separated and not heavily overlapping.
6.2 Effects of Contrast and Illumination Changes
Variations in illumination can shift the histogram and alter the relative positions of class means. If both foreground and background shift similarly, a threshold found from the histogram may remain usable. However, uneven lighting can cause overlapping intensity distributions, weakening between-class separation and producing less reliable thresholds.
6.3 Computational Complexity
For an image with \(L\) grayscale levels, the standard approach evaluates \(L\) candidate thresholds and uses constant-time updates via cumulative sums. The overall time complexity is typically \(O(L)\) after histogram construction, making the method efficient for real-time or batch processing. Memory usage is modest, mainly for the histogram and cumulative arrays.
6.4 Comparison with Other Thresholding Methods
Compared with adaptive thresholding methods (which compute thresholds locally), Otsu’s method is global and may fail when the image contains multiple lighting conditions or spatially varying contrast. Relative to entropy-based thresholding, Otsu’s criterion is simpler to compute and often yields comparable results. When assumptions about bimodality are violated, methods specifically designed for unimodal or multimodal histograms may outperform it.
7 Applications
7.1 Binarization and Foreground Extraction
Otsu’s method is widely used to convert grayscale images into binary masks. By selecting a threshold that separates two histogram regions, it provides a baseline foreground extraction step for downstream processing such as shape analysis, blob detection, or simple object localization.
7.2 Document Scanning and Form Segmentation
In document images, foreground text or markings often contrast with a relatively uniform background. Otsu thresholding can produce effective black-and-white images, improving readability and enabling subsequent operations like connected-component labeling, line detection, or optical character recognition preprocessing.
7.3 Background/Leaf Segmentation in Simple Scenes
In controlled or moderately simple outdoor scenes, objects such as vegetation can appear as a distinct intensity group relative to soil, sky, or pavement. When the histogram shows clear separation, Otsu thresholding can serve as a quick segmentation mechanism for tasks like counting or measuring visible elements.
7.4 Preprocessing for Further Computer Vision Tasks
Thresholded outputs from Otsu’s method can feed into later stages that assume binary inputs, such as morphological filtering, edge refinement, or region-growing algorithms. Although it is not a substitute for robust segmentation in complex environments, it can provide a fast initialization that improves overall pipeline efficiency.