kmeans-color-gpu

Crates.iokmeans-color-gpu
lib.rskmeans-color-gpu
version0.1.0
sourcesrc
created_at2023-09-26 18:36:56.004706
updated_at2023-09-26 18:36:56.004706
descriptionCalculates the average colors in an image for color quantization on the GPU.
homepage
repositoryhttps://github.com/redwarp/k-means-gpu
max_upload_size
id983951
size189,033
BenoƮt Vermont (redwarp)

documentation

README

k-means-gpu

Calculate the k average colors in an image using k-means clustering, leveraging your gpu to do the heavy lifting.

Totally 100% inspired by kmeans-colors.

Turtles

Limitation

As this loads an image as a texture to your graphic cards, it also comes with some limitation based on the GPU backends: It won't work if the original image is bigger than 8192x8192 pixels.

Sample

Tokyo

Create image with colors replaced by their kmeans variant:

cargo run --release -- reduce -i .\gfx\tokyo.png -c 8

Tokyo with k=8

Create a dithered image with colors reduced with kmeans:

cargo run --release -- reduce -i .\gfx\tokyo.png -c 8 -m dither

Tokyo with k=8

Output the palette:

cargo run --release -- palette -i .\gfx\tokyo.png -c 8 -s 40

Tokyo palette with c=8

Find colors and use them as replacement

cargo run --release -- find -i .\gfx\tokyo.png -p "#050505,#ffffff,#ff0000"

Tokyo with looked up colors

Find colors and use them to dither the image

cargo run --release -- find -i .\gfx\tokyo.png -p "#050505,#ffffff,#ff0000" -m dither

Tokyo with looked up colors

Find colors by loading a palette to dither the image

cargo run --release -- find -i .\gfx\tokyo.png -p .\gfx\apollo-1x.png -m dither

Tokyo with looked up colors

Sources

I had to read a bunch of stuff to even start to make sense of it all.

License

MIT

Commit count: 142

cargo fmt