Giter Site home page Giter Site logo

hitherdither's Introduction

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/)

hitherdither's People

Contributors

hbldh avatar astropulse avatar makew0rld avatar

Stargazers

ShuxunoO avatar  avatar Joohun, Maeng avatar

Forkers

voure

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.