#color #quantization #reduce #algorithm #dekker #neuquant #anthony

nightly qwant

Color qwantization library to reduce n colors to 256 colors

2 stable releases

1.0.1 Feb 4, 2025
1.0.0 Mar 9, 2024

#298 in Images

Download history 4/week @ 2024-12-04 12/week @ 2024-12-11 98/week @ 2025-01-29 54/week @ 2025-02-05

152 downloads per month
Used in fimg

MIT license

18KB
285 lines

Color quantization library

This library provides a color quantizer based on the NEUQUANT quantization algorithm by Anthony Dekker.

Usage

let data = vec![[0; 4]; 10];
let nq = qwant::NeuQuant::new(10, 256, &data);
let indixes: Vec<u8> = data.iter().map(|&pix| nq.index_of(pix) as u8).collect();
let color_map: Vec<[u8; 4]> = nq.take_color_map();

lib.rs:

Color quantization library

This library provides a color quantizer based on the NEUQUANT

Original literature: Dekker, A. H. (1994). Kohonen neural networks for optimal colour quantization. Network: Computation in Neural Systems, 5(3), 351-367. doi: 10.1088/0954-898X_5_3_003

See also https://scientificgems.wordpress.com/stuff/neuquant-fast-high-quality-image-quantization/

Usage

let data = vec![[0; 4]; 10];
let nq = qwant::NeuQuant::new(10, 256, &data);
let indixes: Vec<u8> = data.iter().map(|&pix| nq.index_of(pix) as u8).collect();
let color_map: Vec<[u8; 4]> = nq.take_color_map();

Dependencies

~44KB