Thanks to visit codestin.com
Credit goes to lib.rs

#k-means #oklab #palette

no-std okolors

Create color palettes from images by performing k-means clustering in the Oklab color space

12 releases (breaking)

Uses new Rust 2024

0.9.0 Nov 8, 2025
0.8.1 Jul 4, 2024
0.7.0 Mar 21, 2024
0.5.1 Oct 28, 2023
0.3.0 Jun 13, 2023

#435 in Images

MIT/Apache

31KB
262 lines

Okolors

Crate Docs

Okolors generates high quality color palettes from an image for your theming needs. It does this by converting the image's pixels to the Oklab color space and then performing k-means clustering. By using a proper color space for color difference and a more accurate clustering algorithm, this helps to ensure that the generated palette is truly representative of the input image.

If you are looking for the CLI application, see the Github page.

Examples

Here are some examples of palettes generated by Okolors (using the default options).

Louvre

Louvre Louvre Palette

Hokkaido

Hokkaido Hokkaido Palette

Jewel Changi

Jewel Changi Jewel Changi Palette

Český Krumlov

Český Krumlov Český Krumlov Palette

Lake Mendota

Lake Mendota Lake Mendota Palette

Performance

Okolors is designed with performance in mind and should give fast results for even very large images. This is despite using k-means which is more accurate but slower than something like median cut quantization. Below are the palette generation times as reported by the CLI application with the --verbose flag. The only other flag used was -t 4 to use 4 threads. The default/empty RUSTFLAGS were specified.

Image Width Height Time (ms)
Louvre 6056 4000 59
Hokkaido 6000 4000 57
Jewel Changi 6000 4000 61
Český Krumlov 4608 3456 41
Lake Mendota 3839 5758 53

Consider enabling the avx or avx2 target features for a noticeable speedup, since the underlying quantization library (quantette) utilizes SIMD. For more extensive benchmarks, see the README for quantette.

License

Okolors is licensed under either

at your option.

Dependencies

~13MB
~272K SLoC