ColorCruncher: WebAssembly K-Means Color Quantizer
A high-performance color quantization tool using k-means clustering, implemented in Rust and WebGPU
ColorCruncher is a powerful color quantization tool that leverages k-means clustering algorithms to reduce the number of colors in an image while preserving visual quality. Implemented in Rust and compiled to WebAssembly, it offers blazing-fast performance directly in your web browser.
Key Features
- Fast k-means clustering using Hamerly and Lloyd algorithms
- WebAssembly implementation for near-native CPU performance in the browser
- GPU acceleration through WebGPU for even faster processing
- Interactive web interface for easy use and real-time results
How It Works
ColorCruncher uses k-means clustering to group similar colors in the image and replace them with their centroids. The CPU implementation uses the Hamerly algorithm, which vastly improves runtime by uses bounds checks to reduce the number of distance computations. If your browser supports it, you can use GPU acceleration through WebGPU (though this is likely to only be meaningfully faster on very large images).
Technical Details
This project showcases the power of WebAssembly, Rust, and WebGPU in creating high-performance web applications:
- Rust Implementation: The core k-means clustering algorithms (Hamerly and Lloyd) are written in Rust, taking advantage of its speed and memory safety.
- WebAssembly Compilation: The Rust code is compiled to WebAssembly, allowing it to run at near-native speed in web browsers.
- WebGPU Acceleration: GPU implementations of the algorithms are provided through WebGPU, offering significant speedups for compatible devices.
- Web Interface: Built with HTML, CSS, and JavaScript, providing an intuitive way for users to upload images, adjust quantization settings, and see results in real-time.
Source Code
The full source code for ColorCruncher is available on GitHub.