Skip to main content

Dither Go!

Dither Go! is a fast image processing library, making use of dither Golang library to provide the most correct image dithering.

Warning Keep in mind, that this library is currently in alpha state, and although there probably won't be that many breaking changes (unless there will be in dither), there might be some bugs laying around in the less tested parts of the library. If you find some, please report them to the bug tracker.

Features:

  • A vast variety of dithering algorithms built-in with an option to specify your own (under construction),
  • Very fast backend written in Go,
  • Unique correctness from most dithering libraries, thanks to image linearization and color comparisons based on channel weighting technique,
  • Support for images with transparency.

Types of dithering supported

  • Random noise (in grayscale and RGB)
  • Ordered Dithering
    • Bayer matrix of any size (as long as dimensions are powers of two)
    • Clustered-dot - many different preprogrammed matrices
    • Some unusual horizontal or vertical line matrices
    • Yours?
      • Using SetOrdered, this library can dither using any matrix (under construction)
  • Error diffusion dithering
    • Simple 2D
    • Floyd-Steinberg, False Floyd-Steinberg
    • Jarvis-Judice-Ninke
    • Atkinson
    • Stucki
    • Burkes
    • Sierra/Sierra3, Sierra2, Sierra2-4A/Sierra-Lite
    • Steven Pigeon

How to install?

To install Dither Go! from PyPI, setup venv and run:

$ pip install dither-go

And import library using import dither_go.

Usage

Here's a simple example using Floyd-Steinberg dithering:

try:
    img = dither_go.open_image("input.jpg")
except Exception as e:
    print(f"Couldn't load the requested image. Exception: {e}")

# This is the color palette used in output image
palette = dither_go.create_palette([
    [0, 0, 0],
    [255, 255, 255],
    # You can put here any color you want
])

# Create new `Ditherer` object using a constructor
ditherer = dither_go.new_ditherer(palette)
ditherer.Matrix = dither_go.ErrorDiffusers.FloydSteinberg

# Dither the image, attempting to modify the existing image
# If it can't then a dithered copy will be returned.
img = ditherer.Dither(img)

dither_go.save_image(img, "dither_go.png", "png")

If you always want to dither a copy of the image, you can use DitherCopy instead.

Here's how you create a Ditherer that does Bayer dithering. Note that ditherer.SetBayer is used instead of ditherer.Matrix.

ditherer = dither_go.new_ditherer(palette)
ditherer.SetBayer(8, 8, 1.0)  # 8x8 Bayer matrix at 100% strength

Here's how you create a Ditherer that does clustered-dot dithering - dithering with a predefined matrix.

ditherer = dither_go.new_ditherer(palette)
ditherer.SetOrdered(dither_go.OrderedDitherers.ClusteredDotDiagonal8x8, 1.0)

What method should I use?

Generally, using Floyd-Steinberg serpentine dithering will produce the best results. The code would be:

ditherer = dither_go.new_ditherer(palette)
ditherer.Matrix = dither_go.ErrorDiffusers.FloydSteinberg
ditherer.Serpentine = True

Playing with the strength of the matrix might also be useful. The example above is at full strength, but sometimes that's too noisy. The code for 80% strength looks like this:

ditherer.Matrix = dither_go.error_diffusion_strength(dither_go.ErrorDiffusers.FloydSteinberg, 0.8)

The main reason for using any other dithering algorithm would be

  • Aesthetics - dithering can be a cool image effect, and different methods will look different
  • Speed - error diffusion dithering is sequential and therefore single-threaded. But ordered dithering, like using Bayer, will use all available CPUs, which is much faster.

How to access built-in matrices?

Built-in error diffusion and ordered dither matrices are located in ErrorDiffusers and OrderedDitherers data classes.

In order to apply error diffusion matrix to Ditherer, first construct a new instance by using new_ditherer() constructor and set Matrix variable value to any of the ErrorDiffusers matrices.

To apply ordered dither matrix, use SetOrdered method instead.

Warning You can't have both types of dither applied at the same time, so in order to change dithering type, you'll need to clear currently used dither type.

To clear error diffusion matrix, set None as a value in Matrix and to clear ordered dither matrix, use ClearMapper.

How do I get the palette?

Sometimes the palette isn't an option, as it might determined by the hardware. Many e-ink screens can only display black and white for example, and so your palette is chosen for you.

But in most cases you have all the colors available, and so you have to pick the ones that represent your image best. This is called color quantization.

There isn't currently any built-in color quantization functionality available in this library. You'll instead need to use a library for that, like color-thief which is the most popular, or something like colorgram.py or Pylette. There is also pywal which you can use as a module.

Scaling images

A dithered output image will only look right at 100% size. As you scale down, the image will immediately get darker, and strange grid-like artifacts will appear, known as a moiré pattern. This is due to how dithered images work, and is not something this library can fix.

The best thing to do is to scale the input image to the exact size you want before using this library. But sometimes you want to scale the image up after dithering, to make the dithering effect more obvious for aesthetic purposes.

So for scaling the dithered output image up (above 100%), that will only look fine if you use nearest-neighbor scaling - the kind of scaling that produces pixelated results. Otherwise the dither pixel values will be blurred and averaged, which will mess things up. And even once you're using that, it will still produce moiré patterns, unless you're scaling by a multiple of the original dimensions. So when scaling up, you should be scaling by 2x or 3x, rather than a non-integer like 1.34x.

Encoding and decoding

Due to how Golang's image library works, there is only support for the most basic image formats built-in into the standard library.

To add more, you need to use custom decoders/encoders, of which Dither Go! already has several added and a couple planned to be added. You can check the image format matrix to see which are available and planned to be added.

If you want support for a format which isn't currently on that list, submit a feature request in the bug tracker.

Tips:

  • If the palette is grayscale, the input image should be converted to grayscale first to get accurate results.
  • All the [][]uint matrices are supposed to be applied with PixelMapperFromMatrix.
  • You can generate a list of available dither matrices with their display names using MatrixUtils().generate_matrices_list() method.

Notes:

  • This README has some of its parts copied from dither project to provide sufficient information about features of this library

License

This repository is licensed under the terms of the GNU GPLv3 license. You can find a copy of the license in the COPYING file.

The dither library which this project is making use of, is the terms of Mozilla Public License 2.0. The copy of the license can be found here.

Metadata

Release files for dither-go 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dither-go 0.4.0
File Size Uploaded
dither-go-0.4.0.tar.gz 41.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dither-go 0.4.0
File
dither_go-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
dither_go-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
dither_go-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ ARM64 Details
dither_go-0.4.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
dither_go-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.15+ x86-64 Details
dither_go-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
dither_go-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ ARM64 Details
dither_go-0.4.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
dither_go-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.15+ x86-64 Details
dither_go-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
dither_go-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ ARM64 Details
dither_go-0.4.0-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details
dither_go-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details
dither_go-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
dither_go-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ ARM64 Details
dither_go-0.4.0-cp38-cp38-macosx_11_0_arm64.whl CPython 3.8 CPython 3.8 macOS 11.0+ ARM64 Details
dither_go-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.15+ x86-64 Details

Total release size: 31.0 MB

Release files / dither-go-0.4.0.tar.gz

Download URL dither-go-0.4.0.tar.gz
Size 41.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a2da18de3542384667d60dba08ade0492b630002aabe47f492eb73116e39ef4b
BLAKE2b-256 checksum
How to use checksums
014aebf2bce4cb53ce559dd9a3d4ce4d5b1b39bb56d23cbd2aa732bd7ef325c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dither_go-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bbc71f7e1d6086970f25f9833400f437b1aa2b53c914a97582e07353b4a97562
BLAKE2b-256 checksum
How to use checksums
3b73fca02b0e2545ad82f69f9deaf09da1fc50eed85d0072fa221fe52424cad3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dither_go-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5e076a3d2fe1945fe4202e39baa1bc814dbdf4d481f9d74fc01506895cedb942
BLAKE2b-256 checksum
How to use checksums
82323ef2531712bbec6b355da823a24bf3c85e4b779c668d97f28ef6f1ed2e61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dither_go-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
d24d8b3e1053ffb80b30d9aa8697c3c937cffb67fc5c7a6a41f13d84e8bc2372
BLAKE2b-256 checksum
How to use checksums
e83949af3e2332eeb613c2caf59bc2f9f4c540fe5765fd8ed674b565028779d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL dither_go-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
308986de85d763f8b42126411cdd1815ef532868f7652e002431725e847eab47
BLAKE2b-256 checksum
How to use checksums
213c118cf9ac7ccdf2cc2c91c74607136ab4b014598151b0c1b05e0fc0672e84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl

Download URL dither_go-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
162d06c94d907288a8deed96b21470a7bb9ee3293e219395edede223d911ca47
BLAKE2b-256 checksum
How to use checksums
d9eba7888fa38f0d08fb001477b22c7a7b7ffaf34962c1404f73e0a9dc3ef177
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dither_go-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
fdb0054ef1cb4ed9f32326168acaadaa006cbe58b6faef4e5557fd0c574a18d9
BLAKE2b-256 checksum
How to use checksums
9e0fce237548d33808ec9746e796e18fb1e76041f0569f8614dbbae71159df25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dither_go-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
2a8bae961cc72149937add050e73f8ed976a24ba7be4adc7e136be45cf991937
BLAKE2b-256 checksum
How to use checksums
b890c327fa46a5fb096c18cfc7d635dba9b427e714d2cb12cf7ccd5434763aca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL dither_go-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fa564e9c63d6b411d5684c55d4f8b80c1ba682e1a144f3b49898a26cffc02cc0
BLAKE2b-256 checksum
How to use checksums
ded15145f335f1ad7d8328acc7ee22bc0e45de4fe708a671f1d87102dc9613dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl

Download URL dither_go-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
4630f9812a8f9d05e6d3fb971053e1f3fb2eeed11d79749a7746c9f4bad8acb4
BLAKE2b-256 checksum
How to use checksums
94a3888809a0c8ec0c72a34b81598d8166321829d830b6cab311c9313395427e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dither_go-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
347f0d61e9ffe31f8bd021436314c474c6ad4a66af8eea683ae71e341f924ec4
BLAKE2b-256 checksum
How to use checksums
8949e1901926f0691fce565818b5b5ad4e6dcfa4b8bcb12d4bec215402eca3b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dither_go-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
feb2d7e74943ceba6a125dabcd5a47d3d9293c27f9e0d24b50c5a29d8c1b71de
BLAKE2b-256 checksum
How to use checksums
6036714b3e1166a992621bd73e2bcc970b43b4150e88c6bd22a6460e93be25b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp39-cp39-macosx_11_0_arm64.whl

Download URL dither_go-0.4.0-cp39-cp39-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
11a9e206b5a9895fa20903e15437ac1ce8ff508967c3345f90ee9dd653cea49b
BLAKE2b-256 checksum
How to use checksums
2cdf2b33b3c24a00e8134fe0de9765ee31eb33aea3567bebe1da28ec3d389958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl

Download URL dither_go-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
a3ddc89b4a2b652c3353e14ae8f5542d0dd21ceafbb8e6764886b88a07cf6e9e
BLAKE2b-256 checksum
How to use checksums
bab2f7b4d2032349f900dc4d19dff94bf3f588f66aa1cb8628c4ff6189397c82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dither_go-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ce9e0a5b1d5cf584a1e9ecba735d7db426cc228b3fd51c66753dcfdf7f6821e4
BLAKE2b-256 checksum
How to use checksums
3f7b6c0f1c607c8058e2ebf58b8b53a60a6324156b4377576e1953a7a975c9e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dither_go-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
b748151f241a19bd65b5c6cb5051fd42bfc69b53db850d20bef0dd7efbd3a7ff
BLAKE2b-256 checksum
How to use checksums
92ebcb6897a23469252ea928134fa104132c650d90a92043c49fc1e24ce2bde0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp38-cp38-macosx_11_0_arm64.whl

Download URL dither_go-0.4.0-cp38-cp38-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.8 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
43651b4386b797ac3e52e957b1082677b5bc90c2b050e04d33f0dc1c9b076c34
BLAKE2b-256 checksum
How to use checksums
abf46ddcd1d055f50f1c826dad2982a851521ae9281011ec6298d70b981a3b5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / dither_go-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl

Download URL dither_go-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
de90f64f80a8fe162def358e822946bbf2861c3f5449e20bcef5d44c1bf84cf9
BLAKE2b-256 checksum
How to use checksums
4992b1ee20df76eb25dac8eda4aaaf72ffaebd08b2f010731cf869d02d846e81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.4.0 This release

18 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page