Coder Social home page Coder Social logo

okaneco / kmeans-colors Goto Github PK

View Code? Open in Web Editor NEW
125.0 2.0 8.0 535 KB

k-means clustering library and binary to find dominant colors in images

License: Apache License 2.0

Rust 100.00%
kmeans rust color-palette kmeans-clustering image-processing kmeans-colors lab-color dominant-colors dominant-color nearest-colors

kmeans-colors's People

Contributors

barrbrain avatar okaneco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kmeans-colors's Issues

Add `--transparency` support for find/replace

This should look like the main loop functions. It might be possible to split these out into their own functions to be able to reduce/reuse code since they do very similar things.

The main loops in general should be able to be simplified due to generics and similar strategies of calculating results.

Another non issue issue :-)

Hello, communicating again through this because not sure how to!

Inspired by your create, and because I'm super into GPU compute right now for some reason, I've been working on my own version that leverage the GPU to do the heavy lifting.

https://github.com/redwarp/k-means-gpu

It's still quite limited but I wanted to share, because you are totally the inspiration there! It's a lot of fun and I, like, understand 80% of what I'm doing :-D

Does not do kmean++ yet, does only do rgb colors, but it's fast!

Cheers and thanks again.

Thanks for this project!

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

Allow using on lab::Lab

There exists another library on Rust, lab, that has a Lab struct nearly identical to palettes, the main difference being the L*a*b* parameters are f32's rather than generic types and there is no white_point. The same also applies to the LCh struct. I would like to be able to use this struct over the one palette provides, if possible. Cheers.

Hex Colors starting with '0' are not parsed

Hi @okaneco,

first of all: I love the library and cli, really having some fun playing around with it right now, thanks a lot for putting this together!

I found one issue with regards to parsing hex numbers which start with a leading 0 (Zero).
The leading 0 seems to be cut off when parsed as an input given via the '-c' flag.
f.e. '035951' becomes '35951' when parsed as seen in the following screenshot:

image

The Pallette I generated the colors with is this:
pallette_1

Trait not implemented while using palette 0.6

Hello, I've noticed an interesting bug when attempting to use this library with the palette feature enabled. Everything appears to work great when using palette 0.6 but when I attempt to use palette 0.5 I get trait not implemented for Calculate and Hamerly on Lab.

This is main.rs

use kmeans_colors::get_kmeans_hamerly;
use palette::{Lab, Pixel, Srgb};

fn main() {
    let bytes = [0u8, 0, 255, 0, 255, 128];

    let lab: Vec<Lab> = Srgb::from_raw_slice(&bytes)
        .iter()
        .map(|x| x.into_format().into())
        .collect();

    let run_result = get_kmeans_hamerly(8, 20, 5.0, true, &lab, 0);
    println!("{:?}", run_result)
}

and Cargo.toml

[package]
name = "test-kmeans"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.kmeans_colors]
version = "0.4.0"
features = ["palette_color"]
default-features = false

[dependencies.palette]
version = "0.5"
default-features = false
features = ["std"]

This works well, but once you change the palette version to 0.6 and update the code for generating the vector of colors it no longer functions as expected.

Great implementation questions

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

Possible to implement for image::Rgb?

In trying to use get_kmeans(), I attempted to run it on a list of image::Rgb pixels, but it seems to only take palette::lab::Lab or palette::rgb::rgb::Rgb. Is it possible this could be implemented for image::Rgb so I can skip using the palette library?

Palette swatch output

Allow for saving an image that has the k-means colors in swatches. Additionally, there should be an option to append it to the image output, and allow for the swatch sizes to be proportional to their percentage representation in the image (--pct).

Installing from crate.io failed, couldn't compile

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.