
This is the official repository for the paper DocDiff: Document Enhancement via Residual Diffusion Models. DocDiff is a document enhancement model (please refer to the paper) that can be used for tasks such as document deblurring, denoising, binarization, watermark and stamp removal, etc. DocDiff is a lightweight residual prediction-based diffusion model, that can be trained on a batch size of 64 with only 12GB of VRAM at a resolution of 128*128.
Not only for document enhancement, DocDiff can also be used for other img2img tasks, such as natural scene deblurring1, denoising, rain removal, super-resolution2, image inpainting, as well as high-level tasks such as semantic segmentation4.
utils/marker.py and seal dataset. Seal dataset Google Drivedemo/inference.ipynb is uploaded for convenient reproduction and pretrained models checksave/ are uploaded.Whether it's for training or inference, you just need to modify the configuration parameters in conf.yml and run main.py. MODE=1 is for training, MODE=0 is for inference. The parameters in conf.yml have detailed annotations, so you can modify them as needed. Pre-trained weights for document deblurring Coarse Predictor and Denoiser can be found in checksave/, respectively.
Please note that the default parameters in conf.yml work best for document scenarios. If you want to apply DocDiff to natural scenes, please first read Notes! carefully. If you still have issues, welcome to submit an issue.
We provide watermark synthesis code utils/marker.py and a stamp dataset. Seal dataset Google Drive. Since the document background images used are our internal data, we did not provide the background images. If you want to use the watermark synthesis code, you need to find some document background images yourself. The watermark synthesis code is implemented based on OpenCV, so you need to install OpenCV.
The Seal Dataset belongs to the DocDiff project. It contains 1597 red seals in Chinese scenes, along with their corresponding binary masks. These seal data can be used for tasks such as seal synthesis and seal removal. Due to limited manpower, it is extremely difficult to extract seals from document images, so some seal images may contain noise. Most of the original seal images in the dataset are from the ICDAR 2023 Competition on Reading the Seal Title (https://rrc.cvc.uab.es/?ch=20) dataset, and a few are from our internal images. If you find this dataset helpful, please give our project a free star, thank you!!!
conf.yml to use the scheme of predicting $\epsilon$, and modify TIMESTEPS=1000 to use a larger diffusion step.conf.yml. In other words, the scheme of predicting $\epsilon$ is bound to stochastic sampling, while the scheme of predicting $x_0$ is bound to deterministic sampling. If you want to predict $x_0$ and use stochastic sampling, or predict $\epsilon$ and use deterministic sampling, you need to modify the code yourself. In DocDiff, deterministic sampling is performed using the method in DDIM, while stochastic sampling is performed using the method in DDPM. You can modify the code to implement other sampling strategies yourself.@inproceedings{yang2023docdiff,
title={DocDiff: Document Enhancement via Residual Diffusion Models},
author={Yang, Zongyuan and Liu, Baolin and Xxiong, Yongping and Yi, Lan and Wu, Guibin and Tang, Xiaojun and Liu, Ziqi and Zhou, Junjie and Zhang, Xing},
booktitle={Proceedings of the 31st ACM International Conference on Multimedia},
pages={2795--2806},
year={2023}
}
[1] Whang J, Delbracio M, Talebi H, et al. Deblurring via stochastic refinement[C]//Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2022: 16293-16303.
[2] Shang S, Shan Z, Liu G, et al. ResDiff: Combining CNN and Diffusion Model for Image Super-Resolution[J]. arXiv preprint arXiv:2303.08714, 2023.
[3] Song J, Meng C, Ermon S. Denoising diffusion implicit models[J]. arXiv preprint arXiv:2010.02502, 2020.
[4] Wu J, Fang H, Zhang Y, et al. MedSegDiff: Medical Image Segmentation with Diffusion Probabilistic Model[J]. arXiv preprint arXiv:2211.00611, 2022.
[5] Michal Hradiš, Jan Kotera, Pavel Zemčík and Filip Šroubek. Convolutional Neural Networks for Direct Text Deblurring. In Xianghua Xie, Mark W. Jones, and Gary K. L. Tam, editors, Proceedings of the British Machine Vision Conference (BMVC), pages 6.1-6.13. BMVA Press, September 2015.
$ claude mcp add DocDiff \
-- python -m otcore.mcp_server <graph>