Skip to main content

An image binarization library focussing on local adaptive thresholding

Project description

DoxaPy

Introduction

DoxaPy is an image binarization library focussing on local adaptive thresholding algorithms. In English, this means that it has the ability to turn a color or gray scale image into a black and white image.

Algorithms

  • Otsu - "A threshold selection method from gray-level histograms", 1979.
  • Bernsen - "Dynamic thresholding of gray-level images", 1986.
  • Niblack - "An Introduction to Digital Image Processing", 1986.
  • Sauvola - "Adaptive document image binarization", 1999.
  • Wolf - "Extraction and Recognition of Artificial Text in Multimedia Documents", 2003.
  • Gatos - "Adaptive degraded document image binarization", 2005. (Partial)
  • NICK - "Comparison of Niblack inspired Binarization methods for ancient documents", 2009.
  • AdOtsu - "A multi-scale framework for adaptive binarization of degraded document images", 2010.
  • Su - "Binarization of Historical Document Images Using the Local Maximum and Minimum", 2010.
  • T.R. Singh - "A New local Adaptive Thresholding Technique in Binarization", 2011.
  • Bataineh - "An adaptive local binarization method for document images based on a novel thresholding method and dynamic windows", 2011. (unreproducible)
  • ISauvola - "ISauvola: Improved Sauvola's Algorithm for Document Image Binarization", 2016.
  • WAN - "Binarization of Document Image Using Optimum Threshold Modification", 2018.

Optimizations

  • Shafait - "Efficient Implementation of Local Adaptive Thresholding Techniques Using Integral Images", 2008.
  • Petty - An algorithm for efficiently calculating the min and max of a local window. Unpublished, 2019.
  • Chan - "Memory-efficient and fast implementation of local adaptive binarization methods", 2019.

Performance Metrics

  • Overall Accuracy
  • F-Measure
  • Peak Signal-To-Noise Ratio (PSNR)
  • Negative Rate Metric (NRM)
  • Matthews Correlation Coefficient (MCC)
  • Distance-Reciprocal Distortion Measure (DRDM) - "An Objective Distortion Measure for Binary Document Images Based on Human Visual Perception", 2002.

Overview

DoxaPy uses the Δoxa Binarization Framework for quickly processing python Image files.

Example

This short demo uses DoxaPy to read in a color image, converts it to binary, and then compares it to a Ground Truth image in order to calculate performance.

from PIL import Image
import numpy as np
import doxapy

def read_image(file):
    return np.array(Image.open(file).convert('L'))


# Read our target image and setup an output image buffer
grayscale_image = read_image("2JohnC1V3.png")
binary_image = np.empty(grayscale_image.shape, grayscale_image.dtype)

# Pick an algorithm from the DoxaPy library and convert the image to binary
sauvola = doxapy.Binarization(doxapy.Binarization.Algorithms.SAUVOLA)
sauvola.initialize(grayscale_image)
sauvola.to_binary(binary_image, {"window": 75, "k": 0.2})

# Calculate the binarization performance using a Ground Truth image
groundtruth_image = read_image("2JohnC1V3-GroundTruth.png")
performance = doxapy.calculate_performance(groundtruth_image, binary_image)
print(performance)

# Display our resulting image
Image.fromarray(binary_image).show()

Alternative Calls

DoxaPy can very efficiently reuse the same memory buffer for converting a grayscale image to binary. Unless you are constantly changing algorithm parameters for the same image, it is recommended that you call this method.

# Transforms the grayscale image buffer into binary with a single call
doxapy.Binarization.update_to_binary(doxapy.Binarization.Algorithms.NICK, grayscale_image)

Building and Test

DoxaPy supports 64b Linux, Windows, and Mac OSX on Python 3.x. Starting with DoxaPy 0.9.4, Python 3.12 and above are supported with full ABI compatibility. This means that new versions of DoxaPy will only be published due to feature enhancements, not Python version support.

Local Test Setup

clone https://github.com/brandonmpetty/Doxa
cd Doxa/Bindings/Python
pip install -r requirements.txt
python copy-cpp-files.py
cmake -S . -B ./build
cmake --build ./build --config Release
python test/test_doxa.py

Local Package Build

python -m build

License

CC0 - Brandon M. Petty, 2025

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

View Online

"Freely you have received; freely give." - Matt 10:8

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doxapy-0.9.4.tar.gz (39.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

doxapy-0.9.4-cp312-abi3-win_amd64.whl (85.0 kB view details)

Uploaded CPython 3.12+Windows x86-64

doxapy-0.9.4-cp312-abi3-musllinux_1_2_x86_64.whl (529.7 kB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

doxapy-0.9.4-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103.3 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

doxapy-0.9.4-cp312-abi3-macosx_11_0_arm64.whl (75.1 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file doxapy-0.9.4.tar.gz.

File metadata

  • Download URL: doxapy-0.9.4.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for doxapy-0.9.4.tar.gz
Algorithm Hash digest
SHA256 16b2b90d9690cea04185ffd9057b5df56875bd40315833c59871e27efec191fb
MD5 cffd0d03ff9126a99eb9d9805b82dffc
BLAKE2b-256 9ef7f144e68aef05651389a6f31ac0584ee67b4904e147d7d332f3638b83aafa

See more details on using hashes here.

File details

Details for the file doxapy-0.9.4-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: doxapy-0.9.4-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 85.0 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for doxapy-0.9.4-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 de7ad66c089acfb5fcb1100c1cf840ed4fb78a2560b9d697fdbd92bb566665f6
MD5 9b57e89a838d3a34fc918f9537cad93d
BLAKE2b-256 6534e6d529e54fe4f970302e7d65f9eeec6a05b86b1ee82f00114b2bc352faf6

See more details on using hashes here.

File details

Details for the file doxapy-0.9.4-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for doxapy-0.9.4-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 192dce163ee3aa08c8ba380bcb22003912864072755b8df3d8a4cd1faae87b91
MD5 41e47c8d7de440f63409219c8b08a257
BLAKE2b-256 5ab63c7ee4fab0de43b99a2a2e0220b2688b4dd702fb90089e0cd2830b6a7e19

See more details on using hashes here.

File details

Details for the file doxapy-0.9.4-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for doxapy-0.9.4-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f28abaa836068f974a39581411d427f3247bbd7a87ce97a310fcd1a7e9cbae75
MD5 0e8e83f717dadbbfaeba7ce32d571224
BLAKE2b-256 29db74d9d71bc3a28a9b6bfa934937658a9b0c76cb4214b92094005bf0f4890b

See more details on using hashes here.

File details

Details for the file doxapy-0.9.4-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for doxapy-0.9.4-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef57362816eacdb417cfb93bcfcf2c4c1e4e9f15074cf0d3eb55b35f359cd02b
MD5 1338c7d4a8dd4ff8c60742948587cb41
BLAKE2b-256 73128c7a05786743da56d7177f21049df919e92387de6df4ed2e1581dbb82120

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page