Crates.io | color_counter |
lib.rs | color_counter |
version | 0.2.3 |
source | src |
created_at | 2019-02-16 17:44:24.059732 |
updated_at | 2019-11-13 12:12:41.762096 |
description | A crate to inspect an image for most frequent colors. |
homepage | |
repository | https://github.com/aaneto/color_counter.rs |
max_upload_size | |
id | 115193 |
size | 2,329,015 |
A project for getting the color distribution of one image.
The current version works by dividing the CIELAB color space linearly and creating "regions" of colors sorted by frequency.
This command will divide the color space in 10 regions (10% of the dimension each), with 1000 regions in total, display the first 2 regions sorted by their most frequent color, and print the 2 most frequent colors of those regions, using the file forest.jpg.
cargo run -- -r 2 -c 2 -s 0.1 -f forest.jpg
Region 1
Color 1: rgb(142, 146, 113) Frequency: 48
Color 2: rgb(138, 142, 109) Frequency: 36
Region 2
Color 1: rgb(145, 149, 116) Frequency: 48
Color 2: rgb(148, 152, 119) Frequency: 46
To see the options:
cargo run -- --help
While doing this I realised that there is a whole thing about this kind of color extraction, such as color quantization, if I ever come with different implementations it will probably be made into a different crate (color quantize, maybe?).
Another thing to note, the CIELAB space is not linear and linear space division might not be ideal to this problem.
On the lib.rs there is a function called colors_from_bytes, that can be used from a webassembly context, I have tested that to work properly to some degree.