Skip to content
forked from sedthh/pyxelate

Python function that turns images into pixel art.

License

Notifications You must be signed in to change notification settings

Dawars/pyxelate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate pixel arts from images

Pyxelate is a Python class that converts images into tiny pixel arts with limited color palettes.

Definitely not cherry picking

Installation

pip3 install git+https://github.com/sedthh/pyxelate.git

Example usage:

from pyxelate import Pyxelate
from skimage import io
import matplotlib.pyplot as plt

img = io.imread("cat.jpg")
# generate pixel art that is 1/12 the size
height, width, _ = img.shape 
colors = 8
p = Pyxelate(height // 12, width // 12, colors)
img_small = p.convert(img)  # convert img

_, axes = plt.subplots(1, 2, figsize=(16, 16))
axes[0].imshow(img)
axes[1].imshow(img_small)
plt.show()

meow.exe

API

The Pyxelate() class accepts the following init parameters:

  • height: the height of the result image (height was chosen to be first parameter to mirror the array representation)
  • width: the width of the result image
  • color: the number of colors (default is 8)
  • regenerate_palette: if set to False, then the palette will only be generated once, and all future images will be generated using this original palette. This is useful for generating a sequence of images with the same palette (the default value is True, all images will have their own palettes).
  • random_state: the random state for the Bayesian Gaussian Mixture model (default is 0)

Once the class is created, call convert(image) by passing a NumPy array representation of the image.

Details

The method applies a few computer vision functions and simple convolutions on images and selects pixels based on the calculated gradient's magnitude. This was inspired by the Histogram of Oriented Gradients method. Then a Gaussian Mixture model is fitted (instead of conventional K-means) to find a reduced palette based on its components.

Good boye resized

Requirements

The Pyxelate class requires Python 3.7+ and relies on the following libraries to run:

The source code is available under the MIT license.

About

Python function that turns images into pixel art.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%