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.
| Examples | How does it work? | 1.0 checklist |
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
. That Vec
is then sorted by most frequently used colour
to least frequently used. Lets name it palette
for the sake of clarity going
forward.
A separate Vec
, which we'll dub refined_palette
, is now created and it's
from that 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
in refined_palette
.
If there are no colours similar to x
already in refined_palette
, then x
gets added to refined_palette
. If, however, there is a similar colour already
in 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 refined_palette
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 refined_palette
.
- 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
Distil
s. i.e. A way to get oneDistil
from the colours of multiple images.