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

Installing from crate.io failed, couldn't compile #35

Closed redwarp closed 3 years ago

redwarp commented 3 years ago

Wanting to try your tool, I ran cargo install kmeans_colors. It started to download and build the version 0.3.3 from crate.io.

But it ultimately failed, with the following errors:

(...)
   Compiling approx v0.3.2
   Compiling image v0.23.11
   Compiling palette_derive v0.5.0
   Compiling structopt-derive v0.4.13
   Compiling structopt v0.3.20
   Compiling kmeans_colors v0.3.3
error[E0433]: failed to resolve: could not find `CompressionType` in `png`
  --> /Users/bvermont/.cargo/registry/src/github.com-1ecc6299db9ec823/kmeans_colors-0.3.3/src/bin/kmeans_colors/utils.rs:89:25
   |
89 |             image::png::CompressionType::Best,
   |                         ^^^^^^^^^^^^^^^ could not find `CompressionType` in `png`

error[E0433]: failed to resolve: could not find `FilterType` in `png`
  --> /Users/bvermont/.cargo/registry/src/github.com-1ecc6299db9ec823/kmeans_colors-0.3.3/src/bin/kmeans_colors/utils.rs:90:25
   |
90 |             image::png::FilterType::NoFilter,
   |                         ^^^^^^^^^^ could not find `FilterType` in `png`

error[E0433]: failed to resolve: could not find `CompressionType` in `png`
   --> /Users/bvermont/.cargo/registry/src/github.com-1ecc6299db9ec823/kmeans_colors-0.3.3/src/bin/kmeans_colors/utils.rs:127:25
    |
127 |             image::png::CompressionType::Best,
    |                         ^^^^^^^^^^^^^^^ could not find `CompressionType` in `png`

error[E0433]: failed to resolve: could not find `FilterType` in `png`
   --> /Users/bvermont/.cargo/registry/src/github.com-1ecc6299db9ec823/kmeans_colors-0.3.3/src/bin/kmeans_colors/utils.rs:128:25
    |
128 |             image::png::FilterType::NoFilter,
    |                         ^^^^^^^^^^ could not find `FilterType` in `png`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0433`.
error: failed to compile `kmeans_colors v0.3.3`, intermediate artifacts can be found at `/var/folders/s7/jfsvj8x90tq9yf84p62t5vqd4y5v7f/T/cargo-installBCF7Ud`

Caused by:
  could not compile `kmeans_colors`.

To learn more, run the command again with --verbose.

If I check out the repo, building works fine though. So my hunch is that what is published on crate.io might be broken?

okaneco commented 3 years ago

Thanks for the issue! I didn't know this was broken.

It looks like a problem upstream in the image crate. Recently, the png module was moved into a codecs module so instead of the path being image::png, it's now image::codecs::png for the errors you've received. I've submitted an issue for that in image. When installing from cargo, it tries to grab image version "0.23.11" so it fails. When checking out this repo, I've checked in a Cargo.lock with image version "0.23.6" so the build succeeds.

In the meantime, I'll try to update the dependency and offending lines of code. I can push out a new version of this crate when I get the time since I don't like the idea of the crate being broken on crates.io.

okaneco commented 3 years ago

I've published version 0.3.4 to crates.io. I was able to install it successfully. :slightly_smiling_face:

   Compiling palette_derive v0.5.0
   Compiling structopt v0.3.20
   Compiling kmeans_colors v0.3.4
    Finished release [optimized] target(s) in 56.01s
  Installing C:\Users\user\.cargo\bin\kmeans_colors.exe
   Installed package `kmeans_colors v0.3.4` (executable `kmeans_colors.exe`)

I greatly appreciate the report. This same issue prevented another crate of mine from installing, but I've fixed that. I wouldn't have spotted this for a while.

redwarp commented 3 years ago

Thanks for the quick fix! I tried and it works flawlessly. I'm closing this issue then.

redwarp commented 3 years ago

FYI : there is something really cool about running your app through some of my random pictures like Japan 01-08-2013 20-54-35 Japan 01-08-2013 20-54-35-1605560337580-8

okaneco commented 3 years ago

It was a lot of fun to write but more fun to see the results. I've had some thoughts about adding a dithering module to this crate for aesthetics.

A crate I finished recently works well with this crate https://github.com/okaneco/rscolorq. It's in a similar family of algorithms as k-means but dithers based on the pixels around it. It's fairly computationally expensive and doesn't have as clean of convergence criteria, but I like making images with it too. I threw your image into kmeans_colors, then piped the colors into rscolorq and a 50% size copy of the image. It's best to view at full size.

kmeans_colors -i github.jpg -p --no-file
# 13110e,2c2b28,472218,595139,b72c19,748b88,c08d63,dbe4dd
rscolorq -i github.jpg -o github-8c.png -c 13110e,2c2b28,472218,595139,b72c19,748b88,c08d63,dbe4dd

github-8c

And with letting the program find the colors, I've noticed it has some weakness sometimes due to initial choices or lower image contrast.

rscolorq -i github.jpg -o github-8-auto.png --iters 4 --auto                       

github-8-auto

redwarp commented 3 years ago

You... do really cool stuff! It's amazing, I was actually thinking about how to have some nice effect like in the game Return of the Obra Dinn. You could not be more on point! I'm gonna use your rscolorq app and try a few things! Thanks for sharing!

redwarp commented 3 years ago
kmeans_colors.exe -i '.\Japan 01-08-2013 20-54-35.jpg' -k 4 -p --no-file
# 181412,514133,af3b21,bcc3b8
rscolorq.exe -i '.\Japan 01-08-2013 20-54-35.jpg' -c 181412,514133,af3b21,bcc3b8 -o tokyo.png

japan

It looks just great!

okaneco commented 3 years ago

That does look nice. I like that the algorithm has a sort of chunky, high-ISO film grain look when viewed from a slight distance.

If you're interested in Obra Dinn, I know there are some dev blogs about the dithering used. It seems like a blue noise lookup texture on a sphere was used, and there was a temporal aspect that needed to be overcome from player movement (not to mention scaling for different resolutions).

(404'd link in the first post) https://web.archive.org/web/20140214164527/http://home.comcast.net/~ulichney/CV/papers/1993-void-cluster.pdf https://forums.tigsource.com/index.php?topic=40832.msg1045205#msg1045205 https://forums.tigsource.com/index.php?topic=40832.msg1363742#msg1363742

redwarp commented 3 years ago

Thanks for the links! Things like that is one of the reason why I decided to learn rust in the first place: to manipulate image data, and write some algorithm, things I really don't do in my android dev daily job. I'll take a close look at the articles. Let me know if you want some helps for some basic tasks!