ctensmeyer / binarization_2017

BSD 3-Clause "New" or "Revised" License
28 stars 9 forks source link

Binarization

This repo contains the code and models described in Document Image Binarization with Fully Convolutional Neural Networks. There are two sets of 5 models. One trained on DIBCO images, and the other trained on Palm Leaf Manuscripts (PML). Additional info on these models can be found here. You may also be interested in my submission to the DIBCO 2017 competition, located here.

This code depends on a number of python libraries: numpy, scipy, cv2 (python wrapper for opencv), and caffe (my custom fork).

Docker

For those who don't want to install the dependencies, I have created a docker image to run this code. You must have the nvidia-docker plugin installed to use it though you can still run our models on CPU (not recommended).

The usage for the docker container is

nvidia-docker run -v $HOST_WORK_DIRECTORY:/data tensmeyerc/icdar2017:binarization_gpu python binarize_dibco.py /data/input_file.jpg /data/output_file.png $DEVICE_ID
nvidia-docker run -v $HOST_WORK_DIRECTORY:/data tensmeyerc/icdar2017:binarization_gpu python binarize_plm.py /data/input_file.jpg /data/output_file.png $DEVICE_ID

$HOST_WORK_DIRECTORY is a directory on your machine that is mounted on /data inside of the docker container (using -v). It's the only way to expose images to the docker container. $DEVICE_ID is the ID of the GPU you want to use (typically 0). If omitted, then the models are run in CPU mode. There is no need to download the containers ahead of time. If you have docker and nvidia-docker installed, running the above commands will pull the docker image (~2GB) if it has not been previously pulled.

For some reason, the docker image gives a error (related to CuDNN) for binarize_plm.py with all 5 models, so the image was created using only 4 of the models (differeces should be negligible).

Citation

If you find this code useful to your research, please cite our paper:

@inproceedings{tensmeyer2017_binarization,
  title={Document Image Binarization with Fully Convolutional Neural Networks},
  author={Tensmeyer, Chris and Martinez, Tony},
  booktitle={ICDAR},
  year={2017},
  organization={IEEE}
}