Skip to content

Command line utility that generates a color palette based on an image inputed by the user.

License

Notifications You must be signed in to change notification settings

trollLemon/CPlus-palette

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPlus-palette

Command line tool that generates color palettes based on an image given by the user.

Usage

Usage:
 ./cpluspalette: pathToImage -d [numberOfColors] -t [quantization type] <FORMAT>[' ','RGB']
Examples: ./cpluspalette ~/Pictures/picture.png 8 -k RGB
          ./cpluspalette~/Pictures/picture.png 12 -m

quantization types:
-k: uses K mean Clustering for Color Palette Generation: slower but produces better palettes most of the time
-m : used Median Cut for Color Palette Generation: Faster than K mean Clustering but color palettes aren't always as good
FORMAT types:
' ' leave empty for hex color codes
"RGB" for additional RGB color values along with the hex colors

To generate a palette, input a path to an image file, the number of colors you want, and optionally the quantization type: -k: Uses K means Clustering for color quantization -m: Uses Median Cut for color quantization

You can also specify additional formats of the color palette. For example:

./cpluspalette  ~/Pictures/Wallpapers/1.jpg 8 -k RGB   

will output a color palette in hex color codes and rgb values.

By default, Cpluspalette will use K means clustering unless you specify a different quantization type. Generally, the palette quality using K means Clustering is better than what Medain Cut produces but is slower. However, depending on the image, K means Clustering may create a poor palette; in that case, try again using Medain Cut.

Examples

Here is an example. The image in this example was gotten from https://wallpaperaccess.com/abstract-minimalist:

1261697

 cpluspalette 1261697.jpg 8

or

 cpluspalette 1261697.jpg 8 -k

Both ways of running cpluspalette will generate a color palette of 8 colors using K means Clustering:

Generating a 8 color palette from 1261697.jpg... 
Using K Mean Clustering::: 
#f0e889 
#efe289 
#ebe386 
#ebe281 
#b5d09b 
#b4cc92 
#1a646f 
#164454

Here are the following colors from the list above:

1 2 3 4 5 6 7 8

To use Median Cut, run:

 cpluspalette 1261697.jpg 8 -m

Which will generate the following:

Using MedianCut::: 
#825b41 
#9e9066 
#d1d590 
#1c4852 
#c3dfba 
#5fa091 
#185763 
#0e2a39

Here are the colors from the list above:

1 2 3 4 5 6 7 8

Here are some more images with the generated palettes and color quantization type: alena-aenami-endless-1k (image from: https://www.artstation.com/artwork/4bX4eY )

K mean Clustering:

1 2 3 4 5 6 7 8


2test

(image from: https://www.reddit.com/r/WidescreenWallpaper/comments/qy5dvn/abstracts_5160x2160/)

Median Cut::

1 2 3 4


Building

What you need

Packages

All dependencies are included in this repo.

Compilers and Build tools

You will need Cmake and a C++ compiler.

Building

Linux

First, create a directory called build in the GitHub repo and then cd into it:

mkdir build && cd build

Next, configure Cmake and then build the project:

cmake ../
cmake --build .

Then if you want to install it on your system rather than having the executable in the build directory, run the following:

sudo make install

Windows

References

http://ijimt.org/papers/102-M480.pdf https://reasonabledeviations.com/2019/10/02/k-means-in-cpp/ https://curiousily.com/posts/color-palette-extraction-with-k-means-clustering/ https://github.com/ndrake127/kMeans https://muthu.co/reducing-the-number-of-colors-of-an-image-using-median-cut-algorithm/ https://sighack.com/post/averaging-rgb-colors-the-right-way https://www.codespeedy.com/convert-rgb-to-hex-color-code-in-cpp/ https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2