Skip to main content

Convert image into quantized image compatible with Waveshare epaper display

Project description

Install and Test

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_image

with Image.open("tests/data/cliff.jpg") as image:
    quantized_image = quantize_image(image, palette=PALETTES["WAVESHARE-EPD-7COLOR"])
    quantized_image.save("cliffs-quantized.png")

input example image

quantized example image

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

quantized example image

Split by Palette

In some cases such as highlighted here, 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_color

with 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: quantized example image

Single palette color images:

quantized example image quantized example image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image-quantizer-0.0.2.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

image_quantizer-0.0.2-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page