This project demonstrates color compression of images using the K-Means clustering algorithm. The main script main.py
allows you to select an image file, specify the number of colors for compression, and saves the compressed image to an outputs
directory.
- Image Input: Supports PNG, JPG, JPEG, BMP, and GIF images.
- Color Compression: Utilizes K-Means clustering to reduce the number of distinct colors.
- File Size Information: Displays original and compressed image file sizes.
- Output: Saves the compressed image to an
outputs
directory and displays both the original and compressed images side by side.
- Python 3.x
- Pillow (PIL)
- NumPy
- Matplotlib
- scikit-learn
-
Clone the repository:
git clone https://github.com/KIRAN-KUMAR-K3/Image-Color-Compression-using-K-Means.git cd Image-Color-Compression-using-K-Means
-
Install dependencies:
pip install -r requirements.txt
- Ensure you have images in the
images
directory. - Run
main.py
:python main.py
- Follow the prompts to:
- Enter the path to the image file.
- Specify the number of colors for compression.
- Save the compressed image to the
outputs
directory.
- View the original and compressed images, as well as their file sizes.
This project is licensed under the MIT License. See the LICENSE file for details.