Capturing images of documents is one of the easiest and most used methods of recording them. These images however, being captured with the help of handheld devices, often lead to undesirable distortions that are hard to remove. We propose a supervised Gated and Bifurcated Stacked U-Net module to predict a dewarping grid and create a distortion free image from the input. While the network is trained on synthetically warped document images, results are calculated on the basis of real world images. The novelty in our methods exists not only in a bifurcation of the U-Net to help eliminate the intermingling of the grid coordinates, but also in the use of a gated network which adds boundary and other minute line level details to the model. The end-to-end pipeline proposed by us achieves state-of-the-art performance on the DocUNet dataset after being trained on just 8 percent of the data used in previous methods.
Required packages:
To install all required packages, use
pip install -r requirements.txt
Required Directory Structure:
.
+-- data_gen
| +-- .
| +-- image
| +-- label
| +-- image_test
+-- model_save
| +-- .
+-- loader
| +-- .
| +-- __init__.py
| +-- dataset.py
+-- predict
| +-- .
| +-- model_pred.py
| +-- predict.py
+-- unets
| +-- .
| +-- __init__.py
| +-- Punet.py
| +-- Sunet.py
+-- utils
| +-- .
| +-- __init.py
| +-- GCN.py
| +-- plot_me.py
| +-- utils_model.py
+-- model.py
+-- train.py
python3 train.py --batch-size 16
python3 train.py --batch-size 16 --data-path PATH_TO_DATA
python3 train.py -help
mkdir save
cd predict/
python3 predict.py --save-path ../save --img-path IMAGE_PATH --model-path ../model_save/SAVED_MODEL_PATH --multi=False
python3 predict.py --save-path ../save --img-path IMAGE_FOLDER_PATH --model-path ../model_save/SAVED_MODEL_PATH --multi=True
python3 predict.py -help
For generating your own dataset, follow this repository. Do note, they use pkl to save the ground truth dense grid while I make use of npz. To get save arrays as npz, just change the way the grid is saved in the generation code.
model_save
folderpython3 predict.py --save-path save --img-path IMAGE_PATH --model-path model_save/weights.pt --multi=False
If you use this code please consider citing :
@misc{b2020gated,
title={A Gated and Bifurcated Stacked U-Net Module for Document Image Dewarping},
author={Hmrishav Bandyopadhyay and Tanmoy Dasgupta and Nibaran Das and Mita Nasipuri},
year={2020},
eprint={2007.09824},
archivePrefix={arXiv},
primaryClass={cs.CV}
}