Dithering algorithms for arbitrary palettes in PIL
Switch branches/tags
Clone or download
hbldh Version 0.1.5
Fix for #1.
Updated setup.py
Fixed bug due to change in numpy bool array negation.
PEP8 fixes.
Fix for #2.
Added Pipfile.
Updated reqs.
Latest commit f9f435f Nov 28, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
hitherdither Version 0.1.5 Nov 28, 2017
tests Version 0.1.5 Nov 28, 2017
.coveragerc Initial commit Sep 9, 2016
.gitignore Version 0.1.5 Nov 28, 2017
.travis.yml Version 0.1.5 Nov 28, 2017
LICENSE Initial commit Sep 9, 2016
MANIFEST.in Initial commit Sep 9, 2016
Pipfile Version 0.1.5 Nov 28, 2017
Pipfile.lock Version 0.1.5 Nov 28, 2017
README.rst Version 0.1.3 Sep 26, 2016
requirements.txt Version 0.1.5 Nov 28, 2017
run.py Version 0.1.3 Sep 26, 2016
setup.py Version 0.1.5 Nov 28, 2017

README.rst

hitherdither

Build Status Coverage Status

A package inspired by [1], implementing dithering algorithms that can be used with PIL/Pillow.

Description

This module is a small extension to PIL/Pillow, adding a more managable palette object and several dithering algorithms:

  • Error diffusion dithering
    • Floyd-Steinberg
    • Jarvis-Judice-Ninke
    • Stucki
    • Burkes
    • Sierra3
    • Sierra2
    • Sierra-2-4A
    • Stevenson-Arce
    • Atkinson
  • Standard ordered dithering
    • Bayer matrix
    • Cluster dot matrix
    • Arbitrary square threshold matrix (not implemented yet)
  • Yliluoma's ordered dithering (see [1])
    • Algorithm 1
    • Algorithm 2 (not implemented yet)
    • Algorithm 3 (not implemented yet)

The dithering algorithms are applicable for arbitrary palettes and for both RGB and greyscale images.

Installation

pip install git+https://www.github.com/hbldh/hitherdither

Usage

Bayer dithering using a median cut palette:

from PIL import Image
import hitherdither

img = Image.open('image.jpg')
palette = hitherdither.palette.Palette.create_by_median_cut(img)
img_dithered = hitherdither.ordered.bayer.bayer_dithering(
    img, palette, [256/4, 256/4, 256/4], order=8)

Yliluoma's Algorithm 1 using a predefined palette:

from PIL import Image
import hitherdither

palette = hitherdither.palette.Palette(
    [0x080000, 0x201A0B, 0x432817, 0x492910,
     0x234309, 0x5D4F1E, 0x9C6B20, 0xA9220F,
     0x2B347C, 0x2B7409, 0xD0CA40, 0xE8A077,
     0x6A94AB, 0xD5C4B3, 0xFCE76E, 0xFCFAE2]
)

img = Image.open('image.jpg')
img_dithered = hitherdither.ordered.yliluoma.yliluomas_1_ordered_dithering(
    img, palette, order=8)

Tests

Tests can be run with pytest:

hbldh@devbox:~/Repos/hitherdither$ py.test tests
============================= test session starts ==============================
platform linux -- Python 3.5.2, pytest-3.0.2, py-1.4.31, pluggy-0.3.1
rootdir: /home/hbldh/Repos/hitherdither, inifile:
collected 13 items

tests/test_bayer.py ...
tests/test_palette.py ..........

========================== 13 passed in 0.11 seconds ===========================

References

[1](1, 2) Joel Yliluoma's arbitrary-palette positional dithering algorithm (http://bisqwit.iki.fi/story/howto/dither/jy/)