A research implementation for document image dewarping using a hybrid 2D-3D approach with geometric refinement.
This project implements a document dewarping system that combines:
- Dual-stream neural network for initial deformation prediction
- Axis-alignment refinement for geometric perfection
- Hybrid approach blending deep learning with traditional optimization
# Clone the repository
git clone https://github.com/your-username/hyb-gridnet.git
cd hyb-gridnet
# Install dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .import torch
from hyb_gridnet import HybGridNet
# Initialize model
model = HybGridNet(backbone="resnet50", input_size=(512, 512))
# Load and preprocess your image
image = load_image("warped_document.jpg")
# Dewarp the image
dewarped_image, flow_field = model.dewarp(image)
# Save result
save_image(dewarped_image, "rectified_document.jpg")The system consists of two main components:
- Shared encoder (ResNet/ViT) for feature extraction
- 3D shape decoder for global geometry understanding
- 2D flow decoder for local deformation modeling
- Attention fusion to combine both streams
- Line detection to identify structural features
- Geometric optimization to enforce axis-alignment
- Thin-plate splines for smooth interpolation
hyb-gridnet/
├── hyb_gridnet/ # Core package
│ ├── models/ # Neural network architectures
│ ├── modules/ # Core components (AARM, fusion)
│ ├── losses/ # Loss functions
│ ├── data/ # Dataset utilities
│ └── utils/ # Helper functions
├── scripts/ # Training and inference scripts
├── examples/ # Usage examples
└── configs/ # Configuration files
To train the model:
python scripts/train.py --config configs/default.yamlThis is a research implementation. Key features:
- ✅ Dual-stream network architecture
- ✅ Axis-alignment refinement module
- ✅ Basic training pipeline
- 🔄 Pre-trained models (coming soon)
- 🔄 Comprehensive evaluation
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.