DocTr: Document Image Transformer for Geometric Unwarping and Illumination Correction

Hao Feng, Yuechen Wang, Wengang Zhou, Jiajun Deng, Houqiang Li

Introduction

Digitizing physical documents with smartphones is a ubiquitous task, yet the resulting images often suffer from significant geometric and illumination distortions. Folds, curves, and uneven lighting (shadows) degrade the quality of these images, making them unsuitable for downstream tasks like Optical Character Recognition (OCR). While Convolutional Neural Networks (CNNs) have been the standard approach for rectification, their local receptive fields often fail to capture the global context necessary to model complex document deformations.

The DocTr Framework

This paper introduces DocTr, the first Transformer-based framework designed to simultaneously address geometric unwarping and illumination correction. By leveraging the self-attention mechanism, DocTr captures global dependencies across the entire document surface, leading to more accurate and visually pleasing results.

The framework is divided into two specialized components:

Geometric Unwarping Transformer (GeoTr)

GeoTr focuses on flattening the document's shape. It takes a downsampled version of the distorted image and uses a Transformer encoder-decoder architecture to predict a backward mapping field. This field defines how to relocate pixels from the distorted image to a flat canonical plane. To maintain high resolution and sharpness, a learnable "tail" network performs upsampling, avoiding the blurriness typical of standard interpolation methods.

Illumination Correction Transformer (IllTr)

Once the image is geometrically flattened, IllTr addresses lighting inconsistencies. It processes the image in overlapping patches, treating them as sequences. This global-within-patch context allows the model to distinguish between permanent ink and transient shadows, effectively removing the latter while preserving document content.

A rectified receipt demonstrating clean text and uniform illumination after processing by the DocTr framework.

Experimental Results

The authors evaluated DocTr on the DocUNet benchmark, the standard for real-world document rectification.

Qualitative comparison of distorted input images (top) and DocTr-rectified outputs (bottom) across various document types including magazines, receipts, and academic papers.

Quantitative Performance

DocTr achieves state-of-the-art results across multiple metrics:

  • OCR Accuracy: DocTr achieved a Character Error Rate (CER) of 20.02%, representing a 15.32% absolute improvement over previous leading methods like DewarpNet.
  • Geometric Precision: The model reached a lower Local Distortion (LD) score of 8.38, indicating high fidelity in pixel placement.
  • Efficiency: Despite its superior performance, GeoTr is highly efficient, utilizing only 26.9M parameters (approximately 1/3 of DewarpNet's parameter count) and processing 1080p images in 0.13 seconds.

Conclusion and Future Directions

DocTr demonstrates that global context is crucial for document image rectification. By decoupling the tasks of shape and light correction into specialized Transformers, the model achieves unprecedented accuracy and efficiency. Future work may involve incorporating text-aware features to further refine unwarping and exploring full-image Transformers for illumination correction to capture even broader lighting gradients.

Summary updated

BibTeX
@inproceedings{feng2021doctr,
  author = {Hao Feng and Yuechen Wang and Wengang Zhou and Jiajun Deng and Houqiang Li},
  title = {{DocTr: Document Image Transformer for Geometric Unwarping and Illumination Correction}},
  booktitle = {ACM Multimedia},
  year = {2021},
  url = {https://openreview.net/forum?id=DkxAXLIfMd},
}
Figure