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

qwant

Color qwantization library to reduce n colors to 256 colors

1 stable release

1.0.0 Mar 9, 2024

#448 in Images

50 downloads per month
Used in fimg

MIT license

18KB
283 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

~38KB