hquant
High quality quantization for Pillow images.
Pillow uses Euclidean distance for color matching during quantization, which yields poor results when using RGB due to the nonlinearity of color perception. YCbCr is a better fit for Euclidean distance, but Pillow does not natively support quantization of such images.
This module improves the quantization by converting the images to YCbCr, and then tricking Pillow into thinking it's an RGB image so quantization works.
Samples
The following samples dither the original image to the classic 16 colors supported in all terminals, using RGB (as Pillow quantize method would normally use), CIELAB and YCbCr.
| Original | RGB | CIELAB | YCbCr |
|---|---|---|---|
Usage example
from PIL import Image
import hquant
terminal_palette = bytes([
# Primary 3-bit (8 colors). Unique representation!
0x00, 0x00, 0x00,
0x80, 0x00, 0x00,
0x00, 0x80, 0x00,
0x80, 0x80, 0x00,
0x00, 0x00, 0x80,
0x80, 0x00, 0x80,
0x00, 0x80, 0x80,
0xc0, 0xc0, 0xc0,
# Equivalent "bright" versions of original 8 colors.
0x80, 0x80, 0x80,
0xff, 0x00, 0x00,
0x00, 0xff, 0x00,
0xff, 0xff, 0x00,
0x00, 0x00, 0xff,
0xff, 0x00, 0xff,
0x00, 0xff, 0xff,
0xff, 0xff, 0xff,
])
original = Image.open('lena.png')
dithered = hquant.quantize(original, terminal_palette)
dithered.save('dithered.png')
Metadata
Release files for hquant 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hquant-0.1.0.tar.gz | 347.9 kB | Without provenance | Details for hquant-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hquant-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hquant-0.1.0-py3-none-any.whl |
Total release size: 351.2 kB
Release files / hquant-0.1.0.tar.gz
| Download URL | hquant-0.1.0.tar.gz |
|---|---|
| Size | 347.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7e071aa8828e46af36187f1afe405ee66a1cd346b49d14599e42f6fe5da40cc
|
|
BLAKE2b-256 checksum How to use checksums |
3ddf24d0c513565b6099dcd5bf9e5a01ac1877b311eda29dcde1d37747df7746
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / hquant-0.1.0-py3-none-any.whl
| Download URL | hquant-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce249b4626bcf8f12e74b9f0ae2a6a61536f3b54faf855e2e8d3784401a90c7f
|
|
BLAKE2b-256 checksum How to use checksums |
55d2760a4141e7acf491a783ba2fa7e49cc0c828594d8e798ec53dc6e156b168
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Security for hquant 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.