https://github.com/connor-makowski/pixelator
Pixelate images to a specified size and color palette for AI/ML and various other purposes
https://github.com/connor-makowski/pixelator
Last synced: 3 months ago
JSON representation
Pixelate images to a specified size and color palette for AI/ML and various other purposes
- Host: GitHub
- URL: https://github.com/connor-makowski/pixelator
- Owner: connor-makowski
- License: mit
- Created: 2019-10-28T19:26:04.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-14T19:31:19.000Z (4 months ago)
- Last Synced: 2025-03-28T10:21:19.416Z (4 months ago)
- Language: Python
- Size: 298 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://www.python.org/downloads/).
### 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:
```py
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:
```py
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:
```py
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())
```