Skip to content

haydenheroux/kmeans

Repository files navigation

kmeans - stylized images using image segmentation and pixelation

This project implements an algorithm for stylizing images that clusters pixels by color, then maps each cluster to another color. Optionally, the image can be downsampled or have noise added prior to mapping colors, which produces a pixelated or grainy effect when reupscaled.

Demonstrating using the GUI application

Before After
Picture of the Experimental Media and Performing Arts Center (EMPAC) at Rensselaer Polytechnic Institute during the daytime. The same picture of EMPAC after being stylized using pixelation and color clustering.

Photograph taken by Daniel Mennerich (Flickr).

Before
Picture of the Providence, Rhode Island skyline at night.
After
The same picture of the Providence, Rhode Island skyline after being stylized using pixelation and color clustering.

Photograph taken by Macaolards (Wikipedia).

setup

It is recommended to use a virtual environment to manage dependencies.

python -m venv venv
source venv/bin/activate
python -m pip install -r requirements.txt

usage

Using the GUI application allows tuning the pipeline parameters and previewing the effects in real-time.

python gui.py

The CLI application has the same features as the GUI application. Run using the following arguments:

python cli.py <filename> <palette> <pixelsize> <space> <noisesize>

arguments

argument description default value
filename str: The filename of the image to run the algorithm on. None (required)
palette int | str: Either the number of colors to use for an auto-generated palette, or the name of a builtin palette (see palettes). 16
pixelsize int | None: If int, the size of each pixel after reupsampling. If None, no downsampling is performed. None
space str: The color space to run the pipeline in. One of rgb, linear, or oklab. rgb
noisesize number: The amount of noize to add to the image, measured in standard deviations. Effect varies depending on space. 0.0

palettes

palette description
latte Catppuccin Latte
macchiato Catppuccin Macchiato

acknowledgments

About

Stylized image processing in Python using OpenCV.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages