-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible to implement for image::Rgb? #54
Comments
Thanks for the issue, this is a bit of a gap in the library currently and I understand not wanting to use another dependency. The kmeans calculation is done on a floating point component type. When I started this crate, I was originally a little hesitant to support
but I see the value in adding it for users. The current implementation is written in a less clear way than it used to be so it's harder to implement for your own types. I'll work on adding documentation for implementation and annotating the current implementation with comments. This was the previous version of the After this is implemented, you'll need to use Another thought I had was implementing it for SummaryI'll try to add an implementation for |
Awesome! That would save a bunch of the conversion I'm having to do right now. Thanks! |
By the way, this is what I'm using it for: https://github.com/KyleMaas/realworldarchive Specifically, the palette detection: The code quality is horrible on this project - it's very much experimental at this stage - but it does work pretty well. |
I mean, heck, if you could cluster directly on HSL pixels, that'd be pretty awesome, too. But I'd think that would be of far less utility to most people. |
That's why I'll probably implement the traits for something like use bytemuck; // 1.13.1
use image::{ImageBuffer, Rgb32FImage}; // 0.24.6
fn main() {
let data = vec![0_f32, 1., 2., 3., 4., 5.];
let x: Rgb32FImage = ImageBuffer::from_raw(2, 1, data).unwrap();
let y: &[[f32; 3]] = bytemuck::try_cast_slice(x.as_raw()).unwrap();
dbg!(y); // [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0],]
} Thanks for sharing your code, that gives me a better idea of what you're using it for. For the convergence factors, I wish I had a better resource to point to but I ended up at those numbers from experimentation. I know you're interested in removing dependency on Two little things that probably won't matter anyway if you swap out
.map(|x| Srgb::new(x[0], x[1], x[2]).into_format()) // might need ::<_, f32>() annotation This part could probably be rewritten to something like the following. In general with let color: [u8; 3] = c.into_format().into();
colors_rgb.push(Rgb(color));
colors_hsl.push(HSL::from_rgb(&color)); |
I've done a first pass at #56. With this, you'll be able to use it for I have a separate enhancement I want to investigate, but I should be able to push a new update so you don't need |
Cool. Thank you for the pointers. It'll be a little bit before I can test this, but I'll let you know. That'd be great if I could cluster on HSL without normalization - is it possible you could file an issue on that refactor so I can subscribe to it and know when you have it working? |
In trying to use
get_kmeans()
, I attempted to run it on a list ofimage::Rgb
pixels, but it seems to only takepalette::lab::Lab
orpalette::rgb::rgb::Rgb
. Is it possible this could be implemented forimage::Rgb
so I can skip using thepalette
library?The text was updated successfully, but these errors were encountered: