Skip to content

preetmishra/image-compression-kmeans

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Compression using K-Means algorithm.

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.

Comparison

File sizes

ss

Original Image(dog.png) Compressed Image(dog-compressed.png)
Original Image Compressed Image

Requirements

  • Python
  • Scipy
  • Numpy
  • Matplotlib

Instructions

  • Download script.py in your required directory.
  • Run python script.py yourfilenamehere.png in your terminal.

Note

Use a .png file as JPEG uses lossy compression which may lead to undesired result.

Author