Abstract
Document dewarping from a distorted camera-captured image is of great value for OCR and document understanding. The document boundary plays an important role which is more evident than the inner region in document dewarping. Current learning-based methods mainly focus on complete boundary cases, leading to poor document correction performance of documents with incomplete boundaries. In contrast to these methods, this paper proposes MataDoc, the first method focusing on arbitrary boundary document dewarping with margin and text aware regularizations. Specifically, we design the margin regularization by explicitly considering background consistency to enhance boundary perception. Moreover, we introduce word position consistency to keep text lines straight in rectified document images. To produce a comprehensive evaluation of MataDoc, we propose a novel benchmark ArbDoc, mainly consisting of document images with arbitrary boundaries in four typical scenarios. Extensive experiments confirm the superiority of MataDoc with consideration for the incomplete boundary on ArbDoc and also demonstrate the effectiveness of the proposed method on DocUNet, DIR300, and WarpDoc datasets.
Introduction
When capturing documents via mobile devices, the resulting images often suffer from complex geometric distortions caused by paper curvature and camera perspective. Document dewarping aims to digitally flatten these images to improve readability and ensure high-quality Optical Recognition (OCR). While significant progress has been made, most existing learning-based models suffer from a "perfect world" bias: they assume the entire document boundary, including all four corners, is clearly visible within the frame.
In real-world photography, this is rarely the case. Boundaries are often "arbitrary"—they may overflow the image edge, be occluded by a user's thumb, or have missing corners due to folding. When standard models encounter these incomplete boundaries, they struggle to estimate the document's geometry, resulting in warped text lines and distorted edges. MataDoc addresses these challenges by shifting focus toward boundary perception and structural consistency, treating the document boundary as a high-signal geometric anchor that informs the rectification of the entire page.
Methodology
The core of MataDoc is the Dewarp Transformer, an encoder-decoder architecture designed to predict a "backward map" ($z_p$). This map serves as a coordinate grid used to sample pixels from the distorted image to create the final rectified version. To guide the learning process and ensure robustness against arbitrary boundaries, the authors introduce two key regularization techniques:
- Margin-Aware Regularization ($L_M$): The "margin" is defined as the background region in the rectified image. By explicitly enforcing background consistency, the model learns to better perceive where the document ends and the world begins. This is crucial for "hallucinating" or estimating the position of missing edges when the boundary is partially absent from the original photo.
- Text-Aware Regularization ($L_T$): This technique leverages the structural property that text lines should be perfectly straight and horizontal in a flattened document. During training, the system uses an OCR engine to identify text lines and applies a "word position consistency" constraint. This penalizes the model if points belonging to the same text line deviate vertically in the rectified image, effectively using text as a geometric anchor.
The ArbDoc Benchmark
To provide a rigorous evaluation of dewarping in real-world scenarios, the researchers introduced ArbDoc. This benchmark contains 188 real-world images categorized into four typical boundary scenarios:
- Complete: The entire document is visible.
- Overflow: The document extends beyond the image frame.
- Absence: Parts of the document (e.g., corners) are missing or folded.
- Occlusion: The boundary is blocked by external objects like hands or fingers.
ArbDoc includes manual OCR annotations, allowing for precise measurement of how geometric rectification impacts downstream text recognition.
Experimental Results
MataDoc was evaluated against several state-of-the-art (SOTA) models, including DewarpNet, DocTr, and DocGeoNet. Quantitative results on the ArbDoc benchmark demonstrate MataDoc's clear superiority. It achieved a total Edit Distance (ED) of 167.34 and a Character Error Rate (CER) of 0.1695, significantly outperforming the previous best model, DewarpNet, which scored 205.83 and 0.2347, respectively.
Beyond ArbDoc, MataDoc also showed strong performance on the standard DocUNet benchmark and the WarpDoc dataset. On the "incomplete" subset of WarpDoc, MataDoc achieved an ED of 417.29, nearly half that of the next best competitor, DocTr (833.92).
Qualitatively, MataDoc excels at maintaining the parallelism and straightness of text lines, particularly near the edges of the document. While other models often produce "stretched" or curved text when the boundary is incomplete, MataDoc's text-aware constraints keep the layout structurally sound and readable.
Conclusion
MataDoc represents a significant advancement in making document dewarping robust for real-world applications. By explicitly modeling margins and leveraging text lines as geometric anchors, it overcomes the limitations of models trained only on complete boundaries. While the current model focuses on geometric correction, future work could involve integrating illumination correction to handle shadows and glare, as well as optimizing the transformer architecture for real-time performance on mobile devices.
Summary updated