A matrix computations project exploring lossy image compression and optimal reconstruction.
This project implements an image compression pipeline that leverages linear algebra and signal processing techniques to reduce image file sizes while maintaining visual fidelity. By treating image channels as matrices, the application applies Singular Value Decomposition (SVD) to approximate the image with lower-rank matrices. Additionally, Fast Fourier Transform (FFT) is utilized to manipulate image frequencies, allowing for Low-pass (smoothing) and High-pass (sharpening) filtering during the reconstruction process.
The goal is to demonstrate efficient storage methods by decomposing images into their constituent singular values and vectors, storing them in a custom compressed archive, and reconstructing them on demand.
- Channel Separation: Processes Red, Green, and Blue (RGB) channels independently as matrices.
- SVD Compression: Reduces image data redundancy by keeping only the most significant singular values (adjustable compression ratio).
- Frequency Domain Filtering: Implements FFT to apply Gaussian Low-pass and High-pass filters for noise reduction or edge enhancement.
- Custom Artifact Storage: Saves compressed matrix components (
U,S,Vmatrices) and configuration data into a compact.zipformat. - Reconstruction Pipeline: Rebuilds images from compressed artifacts with optional post-processing (sharpening/smoothing).
SAVE.ipynb: The compression module. Loads an image, performs SVD/FFT, and saves the compressed components to a zip file.LOAD.ipynb: The reconstruction module. Reads the zip file, reconstructs the matrices, applies filters, and displays the result.Essentials.py: Helper functions for normalization, Gaussian kernel generation, and visualization.Fourier.py: Functions for applying Fourier Transforms and Inverse Fourier Transforms.Filters.py: Implementation of High-pass and Low-pass filter masks.
-
Clone the repository:
git clone [https://github.com/nikelroid/image-compression.git](https://github.com/nikelroid/image-compression.git) cd image-compression -
Install dependencies: Ensure you have Python installed. Install the required libraries using pip:
pip install numpy opencv-python matplotlib imageio
- Open
SAVE.ipynbin Jupyter Notebook or VS Code. - Set the target image name in the configuration cell (e.g.,
name = 'pepper'). - Adjust compression parameters like
scaleorcomponentthresholds if desired. - Run the notebook. This will generate a
{image_name}.zipfile containing the compressed matrices (U, S, V components) and config.
- Open
LOAD.ipynb. - Ensure the generated
.zipfile is in the same directory. - Set the
namevariable to match your compressed file. - Run the notebook to:
- Extract the matrix components.
- Reconstruct the RGB channels.
- Apply Fourier filters (Highpass/Lowpass) for visual enhancement.
- Display and save the final reconstructed image.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is open-source. MIT License (Suggested).
For questions or feedback regarding the Matrix Computations project, please open an issue in the repository.