A Python-based implementation of lossy image compression leveraging Singular Value Decomposition (SVD) from linear algebra. This project demonstrates how an image can be approximated by keeping only the most significant singular values, drastically reducing file size while preserving essential visual data.
An image can be treated as a large matrix
Where:
-
$U$ is an$m \times m$ orthogonal matrix (left singular vectors). -
$\Sigma$ is an$m \times n$ diagonal matrix containing singular values sorted in descending order ($\sigma_1 \ge \sigma_2 \ge \dots \ge \sigma_r > 0$ ). -
$V^T$ is the transpose of an$n \times n$ orthogonal matrix (right singular vectors).
To compress the image, we truncate these matrices by keeping only the top
As
-
🎛️ Configurable Compression: Adjust the number of singular values (
$k$ ) to control the compression ratio vs. image quality. - 🎨 Grayscale & Color Support: Works seamlessly with both single-channel grayscale images and multi-channel RGB images.
- 📊 Visual Analytics: Generates plots showing the decay of singular values and compares the Original vs. Compressed images side-by-side.
- 📉 Storage Metrics: Calculates and displays the compression ratio and space savings percentage.
- Language: Python 3.x
- Libraries:
NumPy- For handling high-performance matrix operations and computing the SVD.Pillow (PIL)- For image loading, manipulation, and saving.Matplotlib- For plotting the results and visual comparisons.
git clone [https://github.com/YOUR_USERNAME/svd-image-compression.git](https://github.com/YOUR_USERNAME/svd-image-compression.git)
cd svd-image-compression