• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dithering algorithms for arbitrary palettes in PIL

hitherdither

Build and Test 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/)

More Repositories

1

bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
Python
1,527
star
2

pyefd

Python implementation of "Elliptic Fourier Features of a Closed Contour"
Python
79
star
3

pybankid

BankID Relying Party client for Python
Python
45
star
4

pymetawear

Community developed SDK around the Python bindings for the C++ SDK
Python
43
star
5

b2ac

Python and C implementations of an ellipse fitting algorithm in double and fixed point precision.
Python
19
star
6

lspopt

Python implementation of a multitaper window method for estimating Wigner spectra for certain locally stationary processes
Python
19
star
7

skboost

MILBoost and other boosting algorithms, compatible with scikit-learn
Python
13
star
8

calibraxis

Autocalibration method for accelerometer data
Python
11
star
9

xmlr

Python package for parsing very large XML files
Python
10
star
10

pyberryimu

PyBerryIMU - I2C communications lib for using BerryIMU
Python
7
star
11

dlxsudoku

Sudoku Solver written in pure Python with no dependencies
Python
7
star
12

sudokuextract

An image processing tool for extracting Sudokus from images
Python
6
star
13

imdirect

Monkey patch for PIL, performing automatic rotation of opened JPEG images
Python
3
star
14

duckdns-upd8

Python updater for duckdns.org Dynamic DNS record
Python
3
star
15

Uriel

OpenCV based Eye Tracking solution
Python
2
star
16

MongoLab-REST-GAE

A Python REST client for using MongoLab storage in Google App Engine
Python
1
star
17

tpopp

The Point of Pointless Projects
JavaScript
1
star
18

bankkonto

Python validation library for Swedish bank account numbers
Python
1
star
19

PythonBoilerplate

Python project Boilerplate creator.
Python
1
star
20

AdventOfCode

Solutions for Advent of Code 2016 - 2020, written mostly in Python
Python
1
star
21

brotherscan

Tools and documentation on how to get an old Brother Network Printer and Scanner to work
Python
1
star