My implementation of Image Compression by K Means Clustering, in various languages
First, clone this repository. Then, navigate to src/cpp/.
# clean previous build is there are any
rm -rf build
# confiugure and build
cmake -S . -B build
cmake --build build --config Release./build/kmeans_imgc {YOUR_TEST_IMAGE_PATH}.png {K_CLUSETERS: [2,256]} out {JPEG_QUALTIY: [0,100]}Will create the poc compression for the image.
Of course, none other than the first lady of the internet
| Original (474kb/PNG) | Compressed Image w/ 16 Clusters (82kb/JPEG) |
|---|---|
![]() |
![]() |
Prototyping
I've been avoiding Rust for a while, partly due to a "just write in C" mentality and partly because of my general aversion to evangelists. However, my first experience with Rust through WebAssembly was surprisingly positive and measurably faster than native JavaScript. After that Rust conversion therapy, I want to properly learn it as a viable tool. The best way to learn something new is to solve a problem you already understand, letting you focus on implementation rather than figuring out the problem itself.
Building a client-side image compressor. The problem with "free" online converters is that your data ends up on someone else's server where they can do whatever they want with it. TypeScript with Vite is my preferred tool for this kind of web application, and I want to test how well these algorithms perform in the browser.
- Modularize the C++ code. There was too much Stack Overflow involved and proper refactoring would help.
- Add compression performance comparisons.
- Build TypeScript frontend for real-time comparison between original and compressed images.
- Create client-side image compression app for uploading and compressing images.
- Add parameter sliders in the TypeScript client to see compression results in real time.
- Support additional compression algorithms with dropdown selection for users to test different approaches.
- Display metadata for both original and compressed images.
- Support more output formats.
- Expand the TypeScript UI into a full client-side image compression app while maintaining CLI support.

