diff options
author | gennyble <gen@nyble.dev> | 2024-01-16 14:39:10 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-01-16 14:39:10 -0600 |
commit | bbbac45d835dd40c3fb53f8c7f9a2731783841e8 (patch) | |
tree | 617efb0c9561402720630f2996e13ae92efc36ae /src/selection.rs | |
parent | 3b2b22e590a6cfb847eec46eea5977f7a3794ac0 (diff) | |
parent | ecb0519646f6255410a58750c9be394fd20b1f03 (diff) | |
download | colorsquash-bbbac45d835dd40c3fb53f8c7f9a2731783841e8.tar.gz colorsquash-bbbac45d835dd40c3fb53f8c7f9a2731783841e8.zip |
merge novedevo:kmeans (#10)
Diffstat (limited to 'src/selection.rs')
-rw-r--r-- | src/selection.rs | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/selection.rs b/src/selection.rs index 1e27ac4..dacd735 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; #[cfg(feature = "kmeans")] -use kmeans::{KMeans, KMeansConfig}; +use crate::nih_kmeans::KMeans; use rgb::{ComponentBytes, RGB8}; use crate::{ @@ -112,32 +112,7 @@ impl Selector for Kmeans { fn select(&mut self, max_colors: usize, image: ImageData) -> Vec<RGB8> { let ImageData(rgb) = image; - let kmean = KMeans::new( - rgb.as_bytes() - .iter() - .map(|u| *u as f32) - .collect::<Vec<f32>>(), - rgb.as_bytes().len() / 3, - 3, - ); - - let result = kmean.kmeans_lloyd( - max_colors, - 100, - KMeans::init_kmeanplusplus, - &KMeansConfig::default(), - ); - - result - .centroids - .chunks_exact(3) - .map(|rgb| { - RGB8::new( - rgb[0].round() as u8, - rgb[1].round() as u8, - rgb[2].round() as u8, - ) - }) - .collect() + let kmean = KMeans::new(rgb.to_vec()); + kmean.get_k_colors(max_colors, max_iter) } } |