kmeans-colors icon indicating copy to clipboard operation
kmeans-colors copied to clipboard

Great implementation questions

Open bioworldmerch opened this issue 2 years ago • 3 comments

First, this is a great Implementation. I haven't seen any other implementations of the Hamerly method. Couple questions:

  1. convergence factor do you have anymore info on it and how adjustments effect it?
  2. sRGB - the library has an implementation of it you're using to support the color profile. Can you add support for this?
  3. can you point me in the direction of how to save out the executable builds for this? Im not familiar with crates but want to be Thank you

bioworldmerch avatar Mar 18 '22 21:03 bioworldmerch

Thanks. I'll try to answer.

convergence factor do you have anymore info on it and how adjustments effect it?

The convergence factor is a distance metric for how much the centroids have changed from one iteration to the next. Below a threshold, the centroids have moved so little between iterations that it's not visible to us, so it's an optimization to not run more iterations than necessary. A higher factor will have lower quality results because the centroids haven't stabilized yet, but if the factor is too low it may never converge due to the instability of centroids juggling points back and forth between one another.

The convergence factor and maximum number of iterations exist to make sure the algorithm is guaranteed to converge or stop. Through experimenting, I found 0.0025 to be a good factor for RGB and 5.0 for Lab but you can try other values that work for your use.

The documentation could be made more clear about this. There's a bit about it in the bottom of this section.
The binary uses 8 as the default k. The iteration limit is set to 20. The convergence factor defaults to 5.0 for Lab and 0.0025 for Srgb https://docs.rs/kmeans_colors/0.5.0/kmeans_colors/index.html#calculating-k-means

sRGB - the library has an implementation of it you're using to support the color profile. Can you add support for this?

I'm not sure what you mean by this. It's supported in the command line application by passing the --rgb flag. The code examples would look similar but with Lab replaced by Srgb using the palette crate.

can you point me in the direction of how to save out the executable builds for this? Im not familiar with crates but want to be

There are a few ways you can do this, I'm not sure which specifically you mean. You can try downloading from the releases page https://github.com/okaneco/kmeans-colors/releases.

If you cargo install kmeans_colors, the binary will download and compile itself into your .cargo/bin/ folder.

If you're compiling with cargo build --release, the executable will be in the target/release/ folder of your project.

okaneco avatar Mar 20 '22 03:03 okaneco

Thank you. I believe you answered my questions. It sounds to me like your stating For the sRGB portion, --rgb represents sRGB and not the rgb profile. In imagemagick and photoshop, RGB and sRGB are two different profiles.

One more: Can you think of how I could adjust the fuzz value or color average when reducing colors? I get 3 colors typically when two colors are next to each other due to anti-aliasing. For example Yellow/Black next to each other often becomes Yellow, Red and Black colors especially if red is used elsewhere?

bioworldmerch avatar Mar 21 '22 14:03 bioworldmerch

@okaneco This helps a ton for trying to figure out how to use this as a library. Is it possible you might be able to integrate some of this into the documentation?

KyleMaas avatar Jul 29 '23 21:07 KyleMaas