Distil: a colour palette generator
WIP - Not ready for production use
Distil is a Rust library that creates a colour palette from the most frequently used colours in an image.
How does it work?
Lets go through it step by step.
Distil starts by scaling the image down—whilst preserving its aspect ratio—until it consists of no more that 1000 pixels.
From there, it's run through the NeuQuant algorithm to reduce it to an 8-bit image composed of 256 colours.
Next, the number of appearances each unique colour makes in the image is counted
and put into a
Vec is then sorted by most frequently used colour
to least frequently used. Lets name it
palette for the sake of clarity going
Vec, which we'll dub
refined_palette, is now created and it's
Vec that the final palette will be built.
Starting from the top (i.e. the most frequently used colour), the program then
works its way down
palette comparing how similar
x — the current colour from
palette being processed — is by human eye standards to each and every colour
If there are no colours similar to
x already in
gets added to
refined_palette. If, however, there is a similar colour already
refined_palette then an average is made of the two colours which takes into account
their frequency in the image.
The difference between two colours from the human eye perspective is calculated with the CIEDE2000 colour difference algorithm.
With all of the colours now processed, the colours in the
Vec are once again sorted from most frequently used to least frequently used.
An important note here though is that the sorting is done taking into account
the occurrence count of each of the pixels that were deemed similar in colour
and merged together when building
- Handle a pure-white or pure-black image being processed. Pixels that are too dark or too light to be interesting in a palette currently get filtered out during quantization.
- Add a way to create a distillation from multiple
Distils. i.e. A way to get one
Distilfrom the colours of multiple images.