The script uses K-Means, a Machine Learning clustering algorithm, to cluster all the colors in an image into 16 clusters and replace the RGB value of every pixel with the RGB value of their respective cluster center and thus reducing the amount of memory required to save a picture.
Original Image(dog.png) | Compressed Image(dog-compressed.png) |
---|---|
- Python
- Scipy
- Numpy
- Matplotlib
- Download script.py in your required directory.
- Run python script.py yourfilenamehere.png in your terminal.
Use a .png file as JPEG uses lossy compression which may lead to undesired result.
- Preet Mishra LinkedIn