This project demonstrates how K-means clustering can be used to compress images. It applies both non-optimized and optimized versions of the algorithm to iconic test images ("Lena" and "Peppers"). The results highlight how compression reduces file size while preserving visual quality.
-
Python 3.8 or higher
-
Libraries required:
-
NumPy
-
Matplotlib
-
PIL (Python Imaging Library)
-
Clone the repository or download the project files.
-
Install the required dependencies:
- pip install numpy matplotlib pillow
- Open and run the Jupyter Notebook or Python script to process the images.
Lena Images
- Original Image
- Compressed Image (Non-Optimized)
- Compressed Image (Optimized)
Peppers Images
- Original Image
- Compressed Image (Non-Optimized)
- Compressed Image (Optimized)
-
Non-optimized K-means: Implements a basic clustering algorithm for image compression.
-
Optimized K-means: Uses improved techniques for better speed and efficiency.
-
Image Loading: Load images and convert them into arrays using PIL.
-
Clustering:
-
Groups similar pixel intensities using K-means.
-
Iteratively updates cluster centers to minimize variance.
-
Compression: Replaces pixel values with their nearest cluster center.
-
Optimization: Enhances the clustering process for better performance.
-
Visualization: Generates comparisons of the original, non-optimized compressed, and optimized compressed images.
-
K-means Clustering Algorithm
-
Python documentation for NumPy, Matplotlib, and PIL.