Skip to content

Generates a color palette of an given image using k-means clustering

License

Notifications You must be signed in to change notification settings

yulinzheng/color-palette-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

color-palette-generator

A Python script that finds the dominant colors of an given image, and generates a color palette concatenated with the original image. See examples below:

Output images:


Input images:


The RGB values of each color will be printed in the terminal. In "gradient" mode, colors are sorted by the sum of their RGB values. In "frequency" mode, they are sorted by the corresponding cluster size.

"gradient" mode:
"frequency" mode:

Prerequisites

  1. Create a virtual environment and activate it:
$ python3 -m venv .venv
$ source .venv/bin/activate
  1. Install all dependencies:
(.venv) $ pip install -r requirements.txt

Running and Testing

Run the generator with an input image:

(.venv) $ python generator.py /path/to/image

(Optional) Change the number of clusters or the generation mode, for example:

self.CLUSTERS = 7
self.MODE = "frequency"

Deactivate virtual environment if needed:

(.venv) $ deactivate

About

Generates a color palette of an given image using k-means clustering

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages