Document image binarization is the preprocessing step that converts a grayscale or color image of a document into a two-level image, assigning every pixel to either foreground (ink) or background (paper). In document AI, it is one of the oldest and most consequential stages of the pipeline, because errors introduced here, such as broken strokes or merged characters, propagate into OCR, layout analysis and key information extraction.
The task looks simple but becomes hard on real material: uneven illumination, stains, bleed-through from the reverse side, faded ink, low contrast and camera noise all blur the line between text and background. Methods therefore range from a single global threshold to locally adaptive formulas and deep segmentation networks trained on degraded historical documents.
How binarization separates ink from paper
Every binarization method estimates, explicitly or implicitly, a threshold surface T(x, y). A pixel darker than the threshold at its position becomes foreground, and a lighter pixel becomes background. The methods differ in how they estimate that surface: one value for the whole page, a value computed from a local window, or a per-pixel decision learned from data.
A typical pipeline begins with grayscale conversion, optionally followed by background estimation and contrast normalization. The threshold is then applied, and post-processing removes isolated specks, fills small holes in strokes and may smooth character contours. Good results preserve thin strokes and diacritics while suppressing noise.
| Family | How the threshold is set | Strength | Weakness |
|---|---|---|---|
| Global thresholding | One value from the histogram, such as Otsu | Fast and parameter-free | Fails under uneven lighting |
| Local adaptive thresholding | Statistics of a window around each pixel | Handles shading and gradients | Window size must suit text size |
| Hybrid methods | Background estimation plus local rules | Robust on mixed degradation | More parameters to tune |
| Deep learning segmentation | Pixel classification by a trained network | Best on heavy degradation | Needs training data and compute |
Classic thresholding algorithms
Several named algorithms remain standard baselines and are still embedded in production OCR engines. Otsu’s method chooses the global threshold that maximizes between-class variance of the gray-level histogram, which works well for evenly lit, high-contrast scans.
Local methods compute the threshold from the mean and standard deviation within a sliding window. Their parameters control how aggressively faint ink is kept and how much background noise is suppressed, so practitioners tune them to character height and scan resolution.
| Algorithm | Threshold rule | Key parameters | Typical range |
|---|---|---|---|
| Otsu | Maximize between-class variance | None | Not applicable |
| Niblack | Local mean plus k times standard deviation | Window w, factor k | w 15 to 50 px, k about -0.2 |
| Sauvola | Mean times (1 + k(s/R – 1)) | Window w, k, dynamic range R | k 0.2 to 0.5, R 128 |
| Wolf-Jolion | Sauvola normalized by image contrast | Window w, k | k about 0.5 |
| Bernsen | Midpoint of local minimum and maximum | Window w, contrast limit | Contrast limit about 15 |
Sauvola’s method is the most common default for printed documents, because it suppresses background noise much better than Niblack while keeping faint text. A practical rule is to set the window to roughly two to three times the stroke height of body text.
Deep learning approaches
Since about 2017, convolutional encoder-decoder networks such as U-Net variants and fully convolutional networks have led the DIBCO and H-DIBCO competition benchmarks for degraded historical documents. These models treat binarization as semantic segmentation, predicting a foreground probability for every pixel from wide spatial context.
Learned models handle bleed-through, stains and textured paper far better than formulas, but they introduce new risks. They may hallucinate strokes, they depend on the similarity between training and production data, and they cost more to run. Generative adversarial networks and vision transformers have also been applied, mainly for enhancement of severely damaged pages.
- Patch-based inference at 256 or 512 pixels keeps memory use stable on large scans.
- Synthetic degradation of clean pages expands scarce training data.
- Evaluation usually reports F-measure, pseudo F-measure, PSNR and distance reciprocal distortion.
Binarization in modern document AI pipelines
The role of binarization has changed as document AI has evolved. Classic engines such as Tesseract binarize internally before recognition, whereas many neural OCR and OCR-free models read grayscale or color input directly and can lose useful signal if pages are binarized first.
Binarization therefore works best as a deliberate choice per pipeline rather than a fixed habit. It remains valuable for storage compression, legacy engines, form processing and historical archives, and it pairs naturally with document deskewing and dewarping, which also prepare page geometry for recognition.
| Situation | Recommended approach | Reason |
|---|---|---|
| Clean office scans for a legacy OCR engine | Otsu or Sauvola | Fast, accurate, low cost |
| Smartphone photos with shadows | Background normalization plus Sauvola | Removes uneven illumination |
| Degraded historical manuscripts | Trained segmentation network | Handles stains and bleed-through |
| Neural OCR or vision-language models | Skip binarization, keep grayscale | Models use tonal detail |
| Long-term archival storage | Binarize to CCITT G4 or JBIG2 | Large reduction in file size |
Common errors and quality checks
Most binarization failures fall into two groups: lost foreground, where thin or faint strokes disappear, and false foreground, where noise, shadows or bleed-through become black. Both raise the character error rate of downstream OCR.
| Symptom | Likely cause | Correction |
|---|---|---|
| Broken or thin characters | Threshold too low or window too small | Raise k tolerance or enlarge window |
| Black blotches in margins | Shadows under a global threshold | Use local or background-normalized method |
| Mirror text showing through | Bleed-through from the reverse side | Use a learned model or dual-side analysis |
| Speckle noise | Paper texture or low-light camera noise | Median filter and small-component removal |
| Lost colored stamps or highlights | Single-channel grayscale conversion | Choose channel weights per document type |
Teams should measure binarization by its effect on recognition, not only by visual impression. Comparing OCR accuracy on a labeled sample with and without the step quickly shows whether it helps.
Understanding it simply
Document image binarization turns a photo or scan of a page into pure black and pure white. Text becomes black. Everything else becomes white.
This helps reading software find letters. It is like tracing the words of an old, stained letter with a marker on clean paper. The hard part is deciding which gray marks are ink and which are stains, shadows or the faint print showing through from the back.
Applied in practice
A regional archive digitizes about 120,000 pages of nineteenth-century parish registers. The pages are yellowed, some ink has faded to light brown, and many sheets show bleed-through from writing on the reverse side. An initial test with Otsu thresholding produced dark blotches and lost faint entries, and the downstream handwriting recognition made errors on nearly every line.
The digitization team annotated 200 representative pages with ground-truth foreground masks and fine-tuned a U-Net segmentation model, comparing it with Sauvola at a 31-pixel window. On a held-out sample, the learned model raised the F-measure from about 84 to about 93 percent and reduced the character error rate of recognition by roughly a third. The archive kept the original color images for researchers and used the binarized versions only for text recognition and compact search indexes.