{"id":37455638,"url":"https://github.com/redwarp/kmeans-gpu","last_synced_at":"2026-01-16T07:00:21.919Z","repository":{"id":146992002,"uuid":"467700907","full_name":"redwarp/kmeans-gpu","owner":"redwarp","description":"K-means clustering for image color quantization running on GPU","archived":false,"fork":false,"pushed_at":"2023-09-24T16:18:37.000Z","size":9297,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T12:36:52.837Z","etag":null,"topics":["color-quantization","dithering","image-processing","kmeans-clustering","wgpu"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redwarp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-03-08T22:50:53.000Z","updated_at":"2025-03-06T00:16:54.000Z","dependencies_parsed_at":"2023-12-27T14:57:17.810Z","dependency_job_id":null,"html_url":"https://github.com/redwarp/kmeans-gpu","commit_stats":null,"previous_names":["redwarp/k-means-gpu"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/redwarp/kmeans-gpu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redwarp%2Fkmeans-gpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redwarp%2Fkmeans-gpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redwarp%2Fkmeans-gpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redwarp%2Fkmeans-gpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redwarp","download_url":"https://codeload.github.com/redwarp/kmeans-gpu/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redwarp%2Fkmeans-gpu/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color-quantization","dithering","image-processing","kmeans-clustering","wgpu"],"created_at":"2026-01-16T07:00:19.618Z","updated_at":"2026-01-16T07:00:21.750Z","avatar_url":"https://github.com/redwarp.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k-means-gpu\n\nCalculate the k average colors in an image using k-means clustering, leveraging your gpu to do the heavy lifting.\n\nTotally 100% inspired by [kmeans-colors](https://github.com/okaneco/kmeans-colors).\n\n![Turtles](gfx/turtles.gif)\n\n## Limitation\n\nAs 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.\n\n## Sample\n\n![Tokyo](gfx/tokyo.png)\n\n### Create image with colors replaced by their kmeans variant:\n\n```sh\ncargo run --release -- reduce -i .\\gfx\\tokyo.png -c 8\n```\n\n![Tokyo with k=8](gfx/tokyo-reduce-c8-kmeans-replace.png)\n\n### Create a dithered image with colors reduced with kmeans:\n\n```sh\ncargo run --release -- reduce -i .\\gfx\\tokyo.png -c 8 -m dither\n```\n\n![Tokyo with k=8](gfx/tokyo-reduce-c8-kmeans-dither.png)\n\n### Output the palette:\n\n```sh\ncargo run --release -- palette -i .\\gfx\\tokyo.png -c 8 -s 40\n```\n\n![Tokyo palette with c=8](gfx/tokyo-palette-c8-kmeans-s40.png)\n\n### Find colors and use them as replacement\n\n```sh\ncargo run --release -- find -i .\\gfx\\tokyo.png -p \"#050505,#ffffff,#ff0000\"\n```\n\n![Tokyo with looked up colors](gfx/tokyo-find-replace-dark-white-red.png)\n\n### Find colors and use them to dither the image\n\n```sh\ncargo run --release -- find -i .\\gfx\\tokyo.png -p \"#050505,#ffffff,#ff0000\" -m dither\n```\n\n![Tokyo with looked up colors](gfx/tokyo-find-dither-dark-white-red.png)\n\n### Find colors by loading a palette to dither the image\n\n```sh\ncargo run --release -- find -i .\\gfx\\tokyo.png -p .\\gfx\\apollo-1x.png -m dither\n```\n\n![Tokyo with looked up colors](gfx/tokyo-find-dither-apollo.png)\n\n## Sources\n\nI had to read a bunch of stuff to even start to make sense of it all.\n* First of all, the excellent [kmeans-colors](https://github.com/okaneco/kmeans-colors) inspired this project.\n* A few articles from [Muthukrishnan](https://muthu.co/):\n  + https://muthu.co/reduce-the-number-of-colors-of-an-image-using-uniform-quantization/\n  + https://muthu.co/reduce-the-number-of-colors-of-an-image-using-k-means-clustering/\n  + https://muthu.co/mathematics-behind-k-mean-clustering-algorithm/\n* About prefix sum:\n  + https://en.wikipedia.org/wiki/Prefix_sum\n  + Prefix sum in wgsl: https://github.com/googlefonts/compute-shader-101/blob/prefix/compute-shader-hello/src/shader.wgsl\n  + https://github.com/linebender/piet-gpu/blob/prefix/piet-gpu-hal/examples/shader/prefix.comp\n* About dithering:\n  + https://en.wikipedia.org/wiki/Ordered_dithering\n  + http://alex-charlton.com/posts/Dithering_on_the_GPU/\n* Resources:\n  + Resurrect 64 color palette by [Kerrie Lake](https://lospec.com/kerrielake).\n  + Apollo palette by [Adam C Younis](https://lospec.com/adamcyounis)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredwarp%2Fkmeans-gpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredwarp%2Fkmeans-gpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredwarp%2Fkmeans-gpu/lists"}