Abstract
We present Generalized Histogram Thresholding (GHT), a simple, fast, and effective technique for histogram-based image thresholding. GHT works by performing approximate maximum a posteriori estimation of a mixture of Gaussians with appropriate priors. We demonstrate that GHT subsumes three classic thresholding techniques as special cases: Otsu’s method, Minimum Error Thresholding (MET), and weighted percentile thresholding. GHT thereby enables the continuous interpolation between those three algorithms, which allows thresholding accuracy to be improved significantly. GHT also provides a clarifying interpretation of the common practice of coarsening a histogram’s bin width during thresholding. We show that GHT outperforms or matches the performance of all algorithms on a recent challenge for handwritten document image binarization (including deep neural networks trained to produce per-pixel binarizations), and can be implemented in a dozen lines of code or as a trivial modification to Otsu’s method or MET.
Introduction
Image binarization—the process of converting a grayscale image into a binary black-and-white format—is a foundational step in fields ranging from medical imaging to document analysis. For decades, the industry standards have been "global" thresholding methods like Otsu’s method, which minimizes intra-class variance, and Minimum Error Thresholding (MET), which fits a mixture of Gaussians to the image histogram.
However, these classic methods suffer from distinct failure modes. Otsu’s method often fails when foreground and background classes have significantly different sizes or variances. Conversely, MET can become unstable when dealing with sparse histograms. While modern deep learning models can address these issues, they require extensive labeled training data. GHT offers a "middle ground": an algorithm as computationally efficient as the classics but with the Bayesian flexibility to handle complex, real-world data.
Methods: The Bayesian Framework
The core innovation of GHT is framing thresholding as a Maximum A Posteriori (MAP) estimation of a mixture of two Gaussians. The algorithm introduces four hyperparameters that act as "knobs" to control behavior:
- $\nu$ and $\tau$ (Variance Priors): These control the expected variance of the foreground and background.
- $\kappa$ and $\omega$ (Class Balance Priors): These encode prior knowledge about the expected ratio of foreground to background (e.g., assuming a document is mostly white paper rather than ink).
By adjusting these parameters, GHT mathematically unifies existing techniques. MET is equivalent to GHT with no priors. Otsu’s method is the limit of GHT as the variance prior becomes infinitely strong. Weighted percentile thresholding is the limit as the class balance prior becomes dominant. This unification allows researchers to find the "sweet spot" on a continuous spectrum of Bayesian priors.
Key Results and Performance
GHT was evaluated using the 2016 Handwritten Document Image Binarization Contest (H-DIBCO) challenge. The hyperparameters were tuned using a small set of images from the 2013 contest via coordinate descent.
Remarkably, GHT achieved an F1 score of 88.77, significantly outperforming Otsu’s method (86.61) and MET (60.40). Despite being a simple 12-line algorithm that operates on a 256-bin histogram, GHT matched or outperformed several deep neural networks submitted to the contest. This efficiency makes GHT essentially "free" in terms of computational cost compared to the rest of a modern image processing pipeline.
Insights and Limitations
Beyond performance, GHT provides theoretical clarity. The paper demonstrates that the common heuristic of blurring a histogram before thresholding is mathematically equivalent to adjusting the $\tau$ parameter (the variance prior). Furthermore, GHT is robust to mode size; unlike Otsu’s method, which tends to split the larger of two modes in half, GHT’s priors allow it to correctly identify a threshold even when text occupies a tiny fraction of the image.
As a global thresholding method, GHT picks one single value for the entire image. This remains a limitation for images with highly non-uniform backgrounds, such as those with heavy shadows or stains. Future work may involve adapting GHT into a local or adaptive thresholding algorithm by applying these Bayesian priors to sliding windows across the image.
Summary updated