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

ImageProcessing-ElectronicPublications/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

 cpluspalette: pathToImage numberOfColors -t [quantization type]
Example: cpluspalette ~/Pictures/picture.png 8 -m

-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 means Clustering but color palettes aren't always as good

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 2: Uses Median Cut for color quantization

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

You will need CImg, ImageMagick, and the X11 headers installed on your system to build this project.

Compilers and Build tools

You will also need Cmake and the g++ compiler.

The following section includes installation instructions for these packages for different Linux distros.

Arch and Arch-based Distros

On Arch, you can install CImg from the AUR with the following:

yay CImg

and choose the option community/cimg.

Then install ImageMagick, which is available in the official arch repositories:

sudo pacman -S imagemagick

If you do not have the X11 headers, you can install them from the official repository:

sudo pacman -S libx11

Debian and Debian-Based Distros

On Debian (or mint, ubuntu, or other Debian-based distros), install ImageMagick:

sudo apt install ImageMagick

CImg:

sudo apt install cimg-dev

And the X11 headers, if you don't have them:

sudo apt install libx11-dev

Fedora and Fedora-Based Distros

X11 headers:

sudo yum install libX11-dev

Cimg:

sudo dnf install CImg-devel

ImageMagick:

sudo dnf install ImageMagick

Compiling

Once you have gotten CImg, you can compile and link the project.

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

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 94.4%
  • CMake 3.5%
  • C 2.1%