Skip to main content

Pixelate images to a specified size and color palette for AI/ML and various other purposes

Project description

Pixelator

A simple python package to pixelate images given a color palette

Features

  • Users can:
    1. Load in array data, image files or capture directly from a camera
    2. Pixelate images to a specific color palette and image resolution
    3. Access pixelated array data or write it back to an image file

Technical Docs

https://connor-makowski.github.io/pixelator/pixelator.html

Setup

Make sure you have Python 3.6.x (or higher). You can download it here.

Installation

pip install pixelator

Getting Started

Import the pixelator into your project

from pixelator import Pixelator

Some important notes:

  • All data is stored and processed as BGR (to match open cv2)
    • EG: Provided pallettes should be in BGR

Examples

Load from a file:

from pixelator import Pixelator
# Use the input filename provided
image = Pixelator(filename='./images/input.jpg')
# Pixelate the image to a 28x28 black and white array
pixelated_image = image.pixelate(
    width=28,
    height=28,
    palette=[[0,0,0],[255,255,255]]
)
# Write to `output.png` scaled up to a 300x300 image (to be easily viewed)
pixelated_image.write(filename='./images/output_test_1.jpg', width=300, height=300)

Input:

Output:

Capture from a webcam:

from pixelator import Pixelator
# Capture from a webcam since no data or filename is provided
image = Pixelator()

# Pixelate the image to a 64x64 black, white and multiple gray array
pixelated_image = image.pixelate(
    width=64,
    height=64,
    palette=[[0,0,0],[80,80,80],[160,160,160],[200,200,200],[255,255,255]]
)
# Write to `output.png` scaled up to a 500x500 image (to be easily viewed)
pixelated_image.write(filename='./images/output_test_3.jpg', width=300, height=300)

Access Pixelator Data:

from pixelator import Pixelator
# Use the input filename provided
image = Pixelator(filename='./images/input.jpg')
# Pixelate the image to a 28x28 black and white array
pixelated_image = image.pixelate(
    width=28,
    height=28,
    palette=[[0,0,0],[255,255,255]]
)
# Show pixelated image data
print(pixelated_image.data)
# Show Color Counts:
print(pixelated_image.get_color_counts())

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

pixelator-1.2.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

pixelator-1.2.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pixelator-1.2.0.tar.gz.

File metadata

  • Download URL: pixelator-1.2.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pixelator-1.2.0.tar.gz
Algorithm Hash digest
SHA256 89f8560e7067b86fc6a892f930f939f18f30acbf00243a7490deffac7c491d6f
MD5 4a1fb67988b3e1d1b06e527a40cd06e3
BLAKE2b-256 1a67b4b04f4eee58ed37243e01b376c3e4991bb0083a56e13806ce1bf1ecedc8

See more details on using hashes here.

File details

Details for the file pixelator-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pixelator-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pixelator-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ca7adceaf7561d65c642aed543bc33c74aca8b4e49bdc03b6fe893f2368618d
MD5 379052f50dda32c716811a71a60e5316
BLAKE2b-256 db1a269d1a40aa605fa6f6a5a1c88931e0cb29c7c7f914884af6242e1200402d

See more details on using hashes here.

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