pixelator

Pixelator

A simple python package to pixelate images given a BGR 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 and / or write it back to an image file

Technical Docs

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

Setup

Make sure you have Python 3.7.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())
 1"""
 2# Pixelator
 3A simple python package to pixelate images given a BGR color palette
 4
 5## Features
 6
 7- Users can:
 8  1. Load in array data, image files or capture directly from a camera
 9  2. Pixelate images to a specific color palette and image resolution
10  3. Access pixelated array data and / or write it back to an image file
11
12## Technical Docs
13https://connor-makowski.github.io/pixelator/pixelator/pixelator.html
14
15## Setup
16
17Make sure you have Python 3.7.x (or higher). You can download it [here](https://www.python.org/downloads/).
18
19### Installation
20
21```
22pip install pixelator
23```
24
25### Getting Started
26Import the pixelator into your project
27```
28from pixelator import Pixelator
29```
30
31Some important notes:
32- All data is stored and processed as BGR (to match open cv2)
33  - EG: Provided pallettes should be in BGR
34
35### Examples
36
37Load from a file:
38```py
39from pixelator import Pixelator
40# Use the input filename provided
41image = Pixelator(filename='./images/input.jpg')
42# Pixelate the image to a 28x28 black and white array
43pixelated_image = image.pixelate(
44    width=28,
45    height=28,
46    palette=[[0,0,0],[255,255,255]]
47)
48# Write to `output.png` scaled up to a 300x300 image (to be easily viewed)
49pixelated_image.write(filename='./images/output_test_1.jpg', width=300, height=300)
50```
51Input:
52![](images/input.jpg)
53
54Output:
55![](images/output_test_1.jpg)
56
57Capture from a webcam:
58```py
59from pixelator import Pixelator
60# Capture from a webcam since no data or filename is provided
61image = Pixelator()
62
63# Pixelate the image to a 64x64 black, white and multiple gray array
64pixelated_image = image.pixelate(
65    width=64,
66    height=64,
67    palette=[[0,0,0],[80,80,80],[160,160,160],[200,200,200],[255,255,255]]
68)
69# Write to `output.png` scaled up to a 500x500 image (to be easily viewed)
70pixelated_image.write(filename='./images/output_test_3.jpg', width=300, height=300)
71```
72![](images/output_test_3.jpg)
73
74Access Pixelator Data:
75```py
76from pixelator import Pixelator
77# Use the input filename provided
78image = Pixelator(filename='./images/input.jpg')
79# Pixelate the image to a 28x28 black and white array
80pixelated_image = image.pixelate(
81    width=28,
82    height=28,
83    palette=[[0,0,0],[255,255,255]]
84)
85# Show pixelated image data
86print(pixelated_image.data)
87# Show Color Counts:
88print(pixelated_image.get_color_counts())
89```
90"""
91from .pixelator import Pixelator