Water-Filling: An Efficient Algorithm for Digitized Document Shadow Removal

Seungjun Jung, Muhammad Abul Hasan, Changick Kim

TL;DR

The "Water-Filling" algorithm treats document images as 3D topographic maps where shadows are deep valleys. By simulating a physical "immersion" process using diffusion equations, the researchers can accurately estimate and remove complex shading artifacts, significantly improving both visual quality and OCR accuracy compared to existing state-of-the-art methods.

What Problem Does This Paper Address?

While smartphone cameras have replaced flatbed scanners for many, they introduce a major headache: uneven lighting. When you snap a photo of a document, paper folds, hand shadows, and ambient light create "shading artifacts" that make text hard to read and nearly impossible for Optical Character Recognition (OCR) software to process accurately.

Existing solutions usually fall into two camps: binarization (which turns everything into harsh black and white, ruining photos) or mask-and-interpolation (which tries to guess what the background looks like but often fails on complex layouts). The authors sought a method that could handle "generalized" documents—those with varying fonts, large photos, and irregular shadow patterns—without needing to manually mask out text first.

Methods

The core innovation is the Water-Filling analogy. The algorithm follows these steps:

  1. Topographic Mapping: The image’s luminance (brightness) is treated as altitude. Bright pixels are "peaks," and dark pixels (shadows) are "valleys."
  2. The Immersion Process: The authors model the dynamics of water filling these valleys using a novel diffusion equation. They propose two specific techniques:
  3. Incremental Filling: Slowly fills catchment basins (valleys) from the bottom up. It’s precise but slow for large areas.
  4. Flood-and-Effuse: A faster approach where the entire "landscape" is submerged, and water is allowed to "leak" out from the image boundaries.
  5. Boosting with Downsampling: To make the algorithm real-time capable, they use a hybrid approach. They apply the "Flood-and-Effuse" method on a low-resolution version of the image to get a rough sketch of the shadows, then use "Incremental Filling" on the full-resolution image to refine the details.
  6. Reconstruction: Once the "water level" (the background shading) is estimated, they use the Lambertian surface model to divide the original image by the estimated background, effectively "canceling out" the shadows.

Datasets

Because no standard public dataset existed for document shadow removal, the authors created their own:

  • The Main Dataset: 159 digitized documents (109 from smartphones, 50 from scanners).
  • Ground-Truth Pairs: 87 images were captured twice—once in perfect lighting and once with intentional shadows—to allow for precise Peak Signal-to-Noise Ratio (PSNR) measurements.
  • OCR Benchmark: 22 business card images from a public dataset were used to test how much the algorithm improves text recognition.

Key Insights and Ideas

  • The Boundary Condition: The authors observed that in almost all document scans, shadows touch the edge of the frame. By setting the "water level" to zero at the image boundaries, they created a physical constraint that allows the diffusion equation to distinguish between a dark shadow (which connects to the edge) and dark text (which is usually isolated in the center).
  • Luminance as Geometry: Treating light as a physical surface allows the use of fluid dynamics math, which is naturally "smooth." This prevents the blocky artifacts often seen in local thresholding or interpolation methods.
  • Speed vs. Detail: The realization that global shading is "low frequency" allowed them to use downsampling to speed up the process by over 10x without losing the fine details of the text.

Key Results

The Water-Filling algorithm outperformed several state-of-the-art (SOTA) methods across multiple metrics:

  • Image Quality: It achieved a PSNR of 23.38 dB, significantly higher than the next best SOTA method (20.97 dB).
  • OCR Accuracy: Using the "edit-distance" metric (where lower is better), the proposed method scored 9.38, outperforming the best existing method's score of 10.74.
  • Efficiency: While the high-quality version takes about 1.4 seconds, the optimized version (using a higher sampling rate) can process a document in just 0.1 seconds, making it viable for mobile applications.

Limitations and Future Work

The authors identify two main hurdles for future research:

  1. Border-Touching Content: If a piece of text or a photo actually touches the edge of the image, the algorithm might mistake it for a shadow and try to "fill" it, leading to artifacts.
  2. Specular Highlights: The algorithm struggles with "hot spots" or specular reflections (like a camera flash reflecting off glossy paper). Because these areas are overexposed, the original color information is lost, and the Lambertian model cannot perfectly reconstruct what was underneath the glare.

The authors suggest that future iterations will look into integrating geometric de-warping to handle both shadows and paper curls simultaneously.

Summary updated

BibTeX
@inproceedings{jung2018water,
  author = {Seungjun Jung and Muhammad Abul Hasan and Changick Kim},
  title = {{Water-Filling: An Efficient Algorithm for Digitized Document Shadow Removal}},
  booktitle = {ACCV},
  year = {2018},
  url = {https://openreview.net/forum?id=B4PZPUmcwd},
}

Loading related content...

Figure