okaneco / kmeans-colors

k-means clustering library and binary to find dominant colors in images
Apache License 2.0
133 stars 9 forks source link

Thanks for this project! #45

Open alexwlchan opened 2 years ago

alexwlchan commented 2 years ago

I couldn't find a better way to contact you, so have an issue.

Thanks for this project – I've had a Python implementation of kmeans on images for a while, but I wanted to switch to Rust to make it go faster. I thought I might have to implement it myself, then I found your library and decided to try that. It was super easy to get working and saved me a ton of work, thanks!

If you're interested, this is where I'm using it: https://github.com/alexwlchan/dominant_colours

okaneco commented 2 years ago

That's great to hear. Sorry for the late response, somehow I missed a notification.

Your blogs were fun to read because I went down a very relatable path trying to solve a problem. Similar to the PDF problem, I wanted to extract a background color and foreground text color from music cover art. I started with a histogram but the results weren't appealing, and then wrote a simple median-cut implementation. Both had similar issues of favoring the uglier compression artifact pixels over what we see as dominant colors.

I settled on k-means which resulted in this library. I used CIELAB color for the brightest and darkest k-means results, adding/subtracting from their luma component until the sRGB colors reached a suitable WCAG ratio (and ended up adding convenience functions to palette at https://docs.rs/palette/latest/palette/trait.RelativeContrast.html).

To the last point of the dominant colors blog, I completely agree about making tools small enough that you can finish them. Doing one thing and doing it well is something I try to abide by but sometimes features creep in that are convenient for the developer possibly at the expense of the user. :sweat_smile:

shkr commented 2 years ago

@alexwlchan Thank you so much for sharing the message. As someone who is also trying to do more ai stuff on rust, your example repo was a savior

29decibel commented 9 months ago

@okaneco I am here to say thank you as well! ❤️ I was able to create a Elixir wrapper on top of it and using it in Livebook. https://github.com/29decibel/dominant_colors