Skip to content
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

Great implementation questions #50

Open
bioworldmerch opened this issue Mar 18, 2022 · 3 comments
Open

Great implementation questions #50

bioworldmerch opened this issue Mar 18, 2022 · 3 comments

Comments

@bioworldmerch
Copy link

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
@okaneco
Copy link
Owner

okaneco commented Mar 20, 2022

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.

@bioworldmerch
Copy link
Author

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?

@KyleMaas
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants