2023-04-14 00:51:13 +02:00
# sbb_binarization
2020-10-15 14:44:41 +02:00
2024-04-10 16:30:47 +02:00
> Document Image Binarization
2019-12-10 13:00:05 +01:00
2023-04-13 10:50:06 +02:00
[](https://pypi.org/project/sbb-binarization/)
2024-09-30 21:27:04 +02:00
[](https://github.com/qurator-spk/sbb_binarization/actions/workflows/test.yml)
[](https://github.com/qurator-spk/sbb_binarization/actions/workflows/docker-image.yml)
2023-04-13 10:50:06 +02:00
2020-10-29 00:48:03 +01:00
< img src = "https://user-images.githubusercontent.com/952378/63592437-e433e400-c5b1-11e9-9c2d-889c6e93d748.jpg" width = "180" > < img src = "https://user-images.githubusercontent.com/952378/63592435-e433e400-c5b1-11e9-88e4-3e441b61fa67.jpg" width = "180" > < img src = "https://user-images.githubusercontent.com/952378/63592440-e4cc7a80-c5b1-11e9-8964-2cd1b22c87be.jpg" width = "220" > < img src = "https://user-images.githubusercontent.com/952378/63592438-e4cc7a80-c5b1-11e9-86dc-a9e9f8555422.jpg" width = "220" >
2020-10-29 00:45:55 +01:00
2020-01-15 19:49:18 +01:00
## Installation
2020-10-15 14:44:41 +02:00
2024-10-16 18:23:07 +02:00
Python `3.8-3.11` with Tensorflow `<2.13` are currently supported. While newer versions might also work, we currently don't test this.
2020-10-15 14:44:41 +02:00
2024-04-10 16:30:47 +02:00
You can either install from PyPI via
2020-01-15 19:49:18 +01:00
2024-09-30 21:27:04 +02:00
pip install sbb-binarization
2020-10-15 14:44:41 +02:00
2023-04-14 00:51:13 +02:00
or clone the repository, enter it and install (editable) with
2020-10-15 14:44:41 +02:00
2024-09-30 21:27:04 +02:00
git clone git@github .com:qurator-spk/sbb_binarization.git
cd sbb_binarization; pip install -e .
Alternatively, download the prebuilt image from Dockerhub:
docker pull ocrd/sbb_binarization
2020-01-15 19:49:18 +01:00
2023-04-14 00:51:13 +02:00
### Models
2022-10-11 11:37:00 +02:00
2024-04-10 16:30:47 +02:00
Pre-trained models can be downloaded from the locations below. We also provide models and [model cards ](https://huggingface.co/SBB/sbb_binarization ) on 🤗
2022-10-11 11:37:00 +02:00
2024-04-10 16:30:47 +02:00
| Version | Format | Download |
|------------|:-------------:|------------------------------------------------------------------------------------------------------|
2023-04-14 00:51:13 +02:00
| 2021-03-09 | `SavedModel` | https://github.com/qurator-spk/sbb_binarization/releases/download/v0.0.11/saved_model_2021_03_09.zip |
2024-10-17 16:09:42 +02:00
| 2021-03-09 | `HDF5` | https://qurator-data.de/sbb_binarization/2021-03-09/models.tar.gz |
| 2020-01-16 | `SavedModel` | https://github.com/qurator-spk/sbb_binarization/releases/download/v0.0.11/saved_model_2020_01_16.zip |
| 2020-01-16 | `HDF5` | https://qurator-data.de/sbb_binarization/2020-01-16/models.tar.gz |
2023-04-14 00:51:13 +02:00
2024-04-10 16:30:47 +02:00
With [OCR-D ](https://ocr-d.de/ ), you can also use the [Resource Manager ](https://ocr-d.de/en/models ), e.g.
2023-04-12 22:55:12 +02:00
ocrd resmgr download ocrd-sbb-binarize "*"
2020-10-23 19:26:51 +02:00
## Usage
2020-10-15 14:44:41 +02:00
```sh
sbb_binarize \
2023-04-14 00:51:13 +02:00
-m < path to directory containing model files > \
2020-10-23 19:26:51 +02:00
< input image > \
< output image >
2020-10-15 14:44:41 +02:00
```
2020-10-23 19:26:51 +02:00
2023-04-14 00:51:13 +02:00
**Note:** the output image MUST use either `.tif` or `.png` as file extension to produce a binary image. Input images can also be JPEG.
2022-10-11 11:37:00 +02:00
Images containing a lot of border noise (black pixels) should be cropped beforehand to improve the quality of results.
2022-04-25 19:24:04 +02:00
2022-10-11 11:37:00 +02:00
### Example
2022-04-25 19:24:04 +02:00
2021-01-18 15:17:46 +01:00
2023-04-12 22:55:12 +02:00
sbb_binarize -m /path/to/model/ myimage.tif myimage-bin.tif
To use the [OCR-D ](https://ocr-d.de/en/spec/cli ) interface:
ocrd-sbb-binarize -I INPUT_FILE_GRP -O OCR-D-IMG-BIN -P model default
## Testing
For simple smoke tests, the following will
- download models
- download test data
- run the OCR-D wrapper (on page and region level):
2023-04-13 10:50:06 +02:00
2023-04-14 00:51:13 +02:00
make models
2023-04-13 10:50:06 +02:00
make test
2023-04-13 22:33:56 +02:00
2024-10-17 16:09:42 +02:00
## How to cite
If you find this tool useful in your work, please consider citing our paper:
```bibtex
@inproceedings {hip23rezanezhad2,
author = {Vahid Rezanezhad and Konstantin Baierer and Clemens Neudecker},
editor = {Apostolos Antonacopoulos and Christian Clausner and Maud Ehrmann and Kai Labusch and Clemens Neudecker},
title = {A hybrid CNN-Transformer Model for Historical Document Image Binarization},
booktitle = {Proceedings of the 7th International Workshop on Historical Document Imaging and Processing {HIP} 2023,
San José, CA, USA, August 26, 2023},
year = {2023},
url = {https://doi.org/10.1145/3604951.3605508}
}
```