NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Deep Unrestricted Document Image Rectification

Hao Feng, Shaokai Liu, Jiajun Deng, Wengang Zhou, Houqiang Li

TL;DR

DocTr++ is a novel, learning-based framework that rectifies distorted document images without requiring complete document boundaries, making it the first method capable of flattening arbitrary close-ups or cropped text regions. By introducing a hierarchical transformer encoder-decoder architecture and a new "unrestricted" dataset, it significantly outperforms existing methods on partial-view images while running at a real-time speed of over 11 FPS.

What Problem Does This Paper Address?

When you snap a photo of a book page or a document with your smartphone, the paper is often curved, wrinkled, or angled. Document image rectification aims to digitally "flatten" these images to improve readability and downstream OCR (Optical Character Recognition) accuracy.

However, almost all state-of-the-art rectification algorithms share a major flaw: they are boundary-dependent. They assume the input image captures the entire document, using the page edges as critical geometric cues. If you take a close-up shot of a single paragraph or crop out the margins, these algorithms break down.

Three types of document distortions based on boundaries

The authors address this limitation by introducing unrestricted document image rectification, allowing algorithms to successfully flatten images regardless of whether they contain complete, partial, or zero document boundaries (as shown in Figure 1).

Methods

DocTr++ builds upon the authors' previous work (DocTr) but introduces a highly efficient, multi-scale approach to capture internal document structures like textline curvature and texture flow.

Detailed architecture of DocTr++ (Note: Refer to Figure 3 in the paper for the detailed block diagram).

Detailed architecture of DocTr++

The pipeline consists of four main components:

  1. Backbone: A conventional CNN (6 residual blocks) extracts initial 2D feature maps from the distorted image.
  2. Hierarchical Distortion Encoder: Instead of processing features at a single flat scale, this encoder uses three blocks of transformer layers interspersed with convolutional downsampling. This allows the network to capture both fine, high-resolution details and broad, semantically strong structural features while mitigating the heavy computational cost of self-attention on large images.
  3. Rectification Decoder: This module uses a set of learnable queries that attend to the encoder's multi-scale features. Each query learns to become responsible for rectifying a specific patch or region of the image.
  4. Flow Head: A learnable upsampling module transforms the decoder's output into a dense, pixel-wise backward warping flow map ($f_b$). This map dictates exactly how to shift pixels from the distorted image to form the final, flat image via bilinear sampling.

Datasets

Because no dataset existed for unrestricted document rectification, the authors introduced the UDIR (Unrestricted Document Image Rectification) Dataset:

  • Training Set: Created by taking 100k images from the classic Doc3D dataset and randomly cropping them into three distinct categories: (a) complete boundaries, (b) partial boundaries, and (c) no boundaries.
  • Test Set: A real-world benchmark consisting of 195 camera-captured images extended from the DocUNet dataset, manually cropped to evenly represent the three boundary conditions.
Sample images from the UDIR test set

Key Insights and Ideas

  • Internal Cues Over External Boundaries: DocTr++ proves that page boundaries aren't strictly necessary for geometric restoration. By leveraging transformers to model long-range dependencies, the network can infer the underlying 3D page deformation solely from internal cues like textline curvature and shading gradients.
  • The Need for Masked Metrics: Traditional evaluation metrics like Multi-scale Structural Similarity (MS-SSIM) and Local Distortion (LD) fail on cropped document images. Rectifying an incomplete document naturally leaves arbitrary black padding zones where data didn't exist in the source image. To prevent these black zones from skewing evaluation performance, the authors introduced MSSIM-M and LD-M, which mask out invalid regions to ensure a fair comparison.
Illustration of standard vs masked evaluation metrics
  • Hierarchical Efficiency: Transitioning from a flat transformer to a hierarchical encoder-decoder structure effectively reduces the $O(N^2)$ complexity of the self-attention mechanism, yielding a massive boost in inference speed without sacrificing accuracy.

Key Results

DocTr++ achieves state-of-the-art performance across both restricted and unrestricted scenarios:

  • Unrestricted Performance (UDIR Dataset): DocTr++ dramatically outperforms all baseline methods. It achieved an MSSIM-M of 0.45 (compared to DocTr's 0.38) and slashed the local distortion (LD-M) down to 12.47 (a ~33% relative improvement over the next best method).
  • Downstream OCR Impact: On the UDIR dataset, passing raw distorted images through an OCR engine yielded a Character Error Rate (CER) of 39.86%. Rectifying the images with DocTr++ successfully drove the CER down to 22.88%.
  • Speed: DocTr++ processes images at 11.29 FPS, making it significantly faster than the original DocTr (7.40 FPS) and orders of magnitude faster than older architectures like DocUNet (0.21 FPS).

Limitations and Future Work

The authors note that DocTr++ currently encodes geometric representations implicitly. It relies entirely on the neural network's capacity to learn the mapping without explicitly enforcing known physical or geometric constraints (such as mathematically forcing textlines to be straight or parallel in the output).

For future work, the authors plan to explore how incorporating explicit geometric attributes and constraints can further refine the precision and quality of the rectified documents.

Summary updated

BibTeX
@article{feng2024deep,
  author = {Hao Feng and Shaokai Liu and Jiajun Deng and Wengang Zhou and Houqiang Li},
  title = {{Deep Unrestricted Document Image Rectification}},
  journal = {IEEE Trans. Multimedia},
  year = {2024},
  doi = {10.1109/tmm.2023.3347094},
}
Figure