https://github.com/lobis/image-quantizer
Python package 🐍📦 to quantize an image with a customizable palette 🎨. Output is compatible with Waveshare ePaper 📰 displays.
https://github.com/lobis/image-quantizer
actions epaper pillow pypi python waveshare
Last synced: 3 months ago
JSON representation
Python package 🐍📦 to quantize an image with a customizable palette 🎨. Output is compatible with Waveshare ePaper 📰 displays.
- Host: GitHub
- URL: https://github.com/lobis/image-quantizer
- Owner: lobis
- Created: 2022-02-09T15:45:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-02T00:09:12.000Z (over 3 years ago)
- Last Synced: 2025-04-13T19:24:59.193Z (6 months ago)
- Topics: actions, epaper, pillow, pypi, python, waveshare
- Language: Python
- Homepage:
- Size: 1.18 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/lobis/image-quantizer/actions/workflows/python-test.yml)
[](https://badge.fury.io/py/image-quantizer)
# Image Quantizer
Simple Python package to convert an image into a quantized image using a customizable palette. Resulting image can be
displayed by ePaper displays such as Waveshare displays.## Installation
It can be installed as a PyPi package
```
pip install --user image-quantizer
```It can also be installed manually
```
git clone https://github.com/lobis/image-quantizer
cd image-quantizer
python3 setup.py install --user
```## Usage
```
from image_quantizer import quantize_imagewith Image.open("tests/data/cliff.jpg") as image:
quantized_image = quantize_image(image, palette=PALETTES["WAVESHARE-EPD-7COLOR"])
quantized_image.save("cliffs-quantized.png")
```

### Custom palette
```
from image_quantizer import quantize_image, PALETTES# Existing palette names
print(PALETTES)palette = [
[0, 0, 0], # white
[255, 255, 255], # black
[0, 0, 255], # blue
[0, 255, 0], # green
]with Image.open("tests/data/cliff.jpg") as image:
quantized_image_custom = quantize_image(image, palette=palette)
quantized_image_custom.show()
```
### Split by Palette
In some cases such as highlighted [here](https://github.com/lobis/image-quantizer/issues/1), it might be useful to split
an image into its colors. This is necessary to display the image in a waveshare RED-WHITE-BLACK display.```
from image_quantizer import quantize_image, split_image_by_colorwith Image.open("tests/data/cliff.jpg") as image:
quantized_image = quantize_image(image, palette=PALETTES["BLACK-WHITE-RED"])
split_images = split_image_by_color(image)
for color, image in split_images:
image.show()
```Original image:
Single palette color images:

