Skip to content

Palette generator using k-means clustering with CIELAB colors

License

Notifications You must be signed in to change notification settings

gvlsq/palettize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

palettize

Palette generator based on k-means clustering with CIELAB colors.

Palette example

Original photo by Francesco Ungaro from Pexels.

About

This application uses a standard implementation of k-means clustering to generate palettes. The twist is in how colors from the source image are interpreted by the program.

A straightforward implementation might use RGB values directly from the image, but this can lead to issues: the distance function for k-means might indicate that two colors are similar when, perceptually, they are not.

This program transforms colors into CIELAB space before performing any comparisons. The differences between colors should align better with how human eyes actually work, and the resulting palette should be more accurate.

For a description of the k-means algorithm itself, see this YouTube video.

Usage

The following options are accepted on the command line, in order:

  • <source path> - Path to the input image
  • [cluster count] - Number of clusters k used by the algorithm
  • [seed] - Seed used by the algorithm
    • This may be useful if you wanted to re-run the application multiple times under the same conditions
  • [seeding type] - Strategy to choose initial values for the algorithm
    • naive randomly chooses k texels from the input image
    • plusplus uses k-means++ to choose k texels from the input image
      • The initial values are more likely to be spread out, but this option can also take extra time!
  • [sort type] - Metric by which colors in the palette should be sorted, from left to right
    • weight orders by the weight of each color in the input image
    • red orders by the distance of each color from red
    • green orders the colors by the distance of each color from green
    • blue orders the colors by the distance of each color from blue
  • [dest path] - Path used for the output image
    • palette.bmp is used by default

License

See the LICENSE file.

About

Palette generator using k-means clustering with CIELAB colors

Resources

License

Stars

Watchers

Forks

Languages