A fast and the most correct image dithering library
Project description
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)
- Using
- 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 inMatrix
and to clear ordered dither matrix, useClearMapper
.
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 withPixelMapperFromMatrix
. - 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file dither-go-0.4.0.tar.gz
.
File metadata
- Download URL: dither-go-0.4.0.tar.gz
- Upload date:
- Size: 41.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2da18de3542384667d60dba08ade0492b630002aabe47f492eb73116e39ef4b |
|
MD5 | d653fc4c063e2e612d2a310621a52507 |
|
BLAKE2b-256 | 014aebf2bce4cb53ce559dd9a3d4ce4d5b1b39bb56d23cbd2aa732bd7ef325c5 |
File details
Details for the file dither_go-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc71f7e1d6086970f25f9833400f437b1aa2b53c914a97582e07353b4a97562 |
|
MD5 | d460408760c9b9575d649c37735bd678 |
|
BLAKE2b-256 | 3b73fca02b0e2545ad82f69f9deaf09da1fc50eed85d0072fa221fe52424cad3 |
File details
Details for the file dither_go-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e076a3d2fe1945fe4202e39baa1bc814dbdf4d481f9d74fc01506895cedb942 |
|
MD5 | 6bdf1e487c89fdcca9fc0c6bc966f58a |
|
BLAKE2b-256 | 82323ef2531712bbec6b355da823a24bf3c85e4b779c668d97f28ef6f1ed2e61 |
File details
Details for the file dither_go-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d24d8b3e1053ffb80b30d9aa8697c3c937cffb67fc5c7a6a41f13d84e8bc2372 |
|
MD5 | 700f9e88309b9e0a72609f224b3351f0 |
|
BLAKE2b-256 | e83949af3e2332eeb613c2caf59bc2f9f4c540fe5765fd8ed674b565028779d2 |
File details
Details for the file dither_go-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 308986de85d763f8b42126411cdd1815ef532868f7652e002431725e847eab47 |
|
MD5 | 75b305ab275d353e8cf5b7472565fbb8 |
|
BLAKE2b-256 | 213c118cf9ac7ccdf2cc2c91c74607136ab4b014598151b0c1b05e0fc0672e84 |
File details
Details for the file dither_go-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162d06c94d907288a8deed96b21470a7bb9ee3293e219395edede223d911ca47 |
|
MD5 | 88b985933b0f0baba2d99466a418f40f |
|
BLAKE2b-256 | d9eba7888fa38f0d08fb001477b22c7a7b7ffaf34962c1404f73e0a9dc3ef177 |
File details
Details for the file dither_go-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb0054ef1cb4ed9f32326168acaadaa006cbe58b6faef4e5557fd0c574a18d9 |
|
MD5 | ff91526202343c134fe3594ecffb9003 |
|
BLAKE2b-256 | 9e0fce237548d33808ec9746e796e18fb1e76041f0569f8614dbbae71159df25 |
File details
Details for the file dither_go-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a8bae961cc72149937add050e73f8ed976a24ba7be4adc7e136be45cf991937 |
|
MD5 | fa6d8a42af4489139dccd490e8669485 |
|
BLAKE2b-256 | b890c327fa46a5fb096c18cfc7d635dba9b427e714d2cb12cf7ccd5434763aca |
File details
Details for the file dither_go-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa564e9c63d6b411d5684c55d4f8b80c1ba682e1a144f3b49898a26cffc02cc0 |
|
MD5 | 420390f41acce9747cd75cf978fe2433 |
|
BLAKE2b-256 | ded15145f335f1ad7d8328acc7ee22bc0e45de4fe708a671f1d87102dc9613dc |
File details
Details for the file dither_go-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4630f9812a8f9d05e6d3fb971053e1f3fb2eeed11d79749a7746c9f4bad8acb4 |
|
MD5 | 560d4656de9f128bd81fe498fe353298 |
|
BLAKE2b-256 | 94a3888809a0c8ec0c72a34b81598d8166321829d830b6cab311c9313395427e |
File details
Details for the file dither_go-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 347f0d61e9ffe31f8bd021436314c474c6ad4a66af8eea683ae71e341f924ec4 |
|
MD5 | 04241df8e74a56dadb7700b7ed922bff |
|
BLAKE2b-256 | 8949e1901926f0691fce565818b5b5ad4e6dcfa4b8bcb12d4bec215402eca3b2 |
File details
Details for the file dither_go-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | feb2d7e74943ceba6a125dabcd5a47d3d9293c27f9e0d24b50c5a29d8c1b71de |
|
MD5 | 9474bc67ad244d72fed5a156b7802f51 |
|
BLAKE2b-256 | 6036714b3e1166a992621bd73e2bcc970b43b4150e88c6bd22a6460e93be25b4 |
File details
Details for the file dither_go-0.4.0-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a9e206b5a9895fa20903e15437ac1ce8ff508967c3345f90ee9dd653cea49b |
|
MD5 | 3c9a704a66fb0b0ab5c74f6f8f6dca6b |
|
BLAKE2b-256 | 2cdf2b33b3c24a00e8134fe0de9765ee31eb33aea3567bebe1da28ec3d389958 |
File details
Details for the file dither_go-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3ddc89b4a2b652c3353e14ae8f5542d0dd21ceafbb8e6764886b88a07cf6e9e |
|
MD5 | 82b69088d53150bc61be1406c0cc7df0 |
|
BLAKE2b-256 | bab2f7b4d2032349f900dc4d19dff94bf3f588f66aa1cb8628c4ff6189397c82 |
File details
Details for the file dither_go-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce9e0a5b1d5cf584a1e9ecba735d7db426cc228b3fd51c66753dcfdf7f6821e4 |
|
MD5 | dbc4b60696441b4490f9a72d9efbec46 |
|
BLAKE2b-256 | 3f7b6c0f1c607c8058e2ebf58b8b53a60a6324156b4377576e1953a7a975c9e3 |
File details
Details for the file dither_go-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b748151f241a19bd65b5c6cb5051fd42bfc69b53db850d20bef0dd7efbd3a7ff |
|
MD5 | 6ce28e9f0ab515926289f57e31fe02dd |
|
BLAKE2b-256 | 92ebcb6897a23469252ea928134fa104132c650d90a92043c49fc1e24ce2bde0 |
File details
Details for the file dither_go-0.4.0-cp38-cp38-macosx_11_0_arm64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43651b4386b797ac3e52e957b1082677b5bc90c2b050e04d33f0dc1c9b076c34 |
|
MD5 | cb88c79d5488e644b5e9d5b0ea86d669 |
|
BLAKE2b-256 | abf46ddcd1d055f50f1c826dad2982a851521ae9281011ec6298d70b981a3b5a |
File details
Details for the file dither_go-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: dither_go-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de90f64f80a8fe162def358e822946bbf2861c3f5449e20bcef5d44c1bf84cf9 |
|
MD5 | cf1eebb8685bf7f7ec37f68a1af8825e |
|
BLAKE2b-256 | 4992b1ee20df76eb25dac8eda4aaaf72ffaebd08b2f010731cf869d02d846e81 |