Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Compression using SVD (Singular Value Decomposition) 🖼️📉

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.


🧮 How It Works (The Math)

An image can be treated as a large matrix $A$ of pixel values (or three matrices for RGB channels). SVD factorizes this matrix $A$ of dimensions $m \times n$ into three constituent matrices:

$$A = U \Sigma V^T$$

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).

Low-Rank Approximation

To compress the image, we truncate these matrices by keeping only the top $k$ singular values (where $k \ll \min(m, n)$). The compressed image matrix $A_k$ is calculated as:

$$A_k = \sum_{i=1}^{k} \sigma_i u_i v_i^T$$

As $k$ increases, the image quality improves, but the file storage requirement increases.


✨ Features

  • 🎛️ 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.

🛠️ Tech Stack & Dependencies

  • 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.

🚀 Getting Started

1. Clone the Repository

git clone [https://github.com/YOUR_USERNAME/svd-image-compression.git](https://github.com/YOUR_USERNAME/svd-image-compression.git)
cd svd-image-compression

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages