A Python project that performs image compression using Singular Value Decomposition (SVD) on the RGB channels of a color image.
- Reads and displays any color image
- Splits image into Red, Green, and Blue channels
- Applies SVD on each channel
- Reconstructs the image using the top
ksingular values - Displays and saves the compressed image
- Original and compressed image comparison (shown via OpenCV GUI)
- Matrix shape and values printed for debugging and learning purposes
- Image is split into RGB channels.
- SVD is performed on each channel.
- Each channel is reconstructed using only the top
ksingular values. - The channels are merged to create the compressed image.
svd_image_compression/
βββ image_compression.py # Main Python script
βββ example.jpg # (Optional) Sample input image
βββ README.md # This file
Install required packages using:
pip install numpy opencv-pythonpython image_compression.pyThen follow the prompts:
- Enter the path to your input image
- Enter the value of
k(number of singular values to retain) - Provide a save path for the compressed output
Enter the image path: example.jpg
Enter the value of k: 50
Enter Output Path: ./output/
SVD helps reduce image size while retaining important features:
- Lower
kmeans more compression (less detail). - Higher
kretains more image quality.
| k Value | File Size | Quality |
|---|---|---|
| 50 | Smaller | Blurry |
| 200 | Larger | Clear |