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.
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
Create image with colors replaced by their kmeans variant:
Create a dithered image with colors reduced with kmeans:
Output the palette:
Find colors and use them as replacement
Find colors and use them to dither the image
Find colors by loading a palette to dither the image
Sources
I had to read a bunch of stuff to even start to make sense of it all.
- First of all, the excellent kmeans-colors inspired this project.
- A few articles from Muthukrishnan:
- About prefix sum:
- About dithering:
- Resources:
- Resurrect 64 color palette by Kerrie Lake.
- Apollo palette by Adam C Younis
License
MIT