This project demonstrates image compression using the Discrete Cosine Transform (DCT). It provides a graphical user interface (GUI) to load, compress, and visualize BMP images. Additionally, it compares the performance of manual and library-based DCT implementations across various matrix sizes.
To ensure that you have all the necessary dependencies, a virtual environment should be created and activated before running the project. Follow these steps to set up your environment:
-
Create a virtual environment:
python -m venv env
-
Activate the virtual environment:
-
On Windows:
.\env\Scripts\activate
-
On macOS and Linux:
source env/bin/activate
-
-
Install the required packages:
pip install -r requirements.txt
The following Python packages are required for this project:
tkinter
Pillow
numpy
matplotlib
scipy
Ensure that these packages are installed in your environment. A requirements.txt
file is provided for convenience.
The project is divided into several modules to organize the code effectively:
-
GUI and Main Application (
main.py
):- This module initializes the main window using Tkinter, loads images, processes compression, and manages user interactions.
-
DCT Algorithms (
dct_algorithms.py
):- Contains both manual and library-based implementations of 2D DCT and IDCT.
-
Image Processing (
image_processing.py
):- Handles image conversion to/from matrices, DCT application, and filtering frequencies.
-
Performance Comparison (
compare_performance.py
):- Measures and compares the performance of manual and library-based DCT algorithms.
-
Start the application:
bash
Copia codice
python dct_image_processor.py
-
Load an Image:
- Click on "Load .bmp image" to select a BMP file.
- Adjust the parameters
F
(block size) andd
(frequency cut-off) if needed.
-
Compress the Image:
- The application will display the original and compressed images side by side.
- Compression details, including original size, compressed size, and compression ratio, will be shown.
-
Compare DCT2 Algorithms:
- Navigate to the "Comp" tab.
- Click on "Compare DCT2 Algorithms" to start the performance comparison.
- A progress bar will indicate the status, and a plot will display the results once completed.
- F (Block Size): Determines the size of the blocks for DCT transformation. Default is 10.
- d (Frequency Cut-off): Specifies the threshold for filtering frequencies during compression. Default is 7.
- Check the "Normalize DCT Coefficients" option to enable normalization of DCT coefficients.
-
Progress and Visualization:
- The progress of DCT algorithm comparison is shown using a progress bar.
- The comparison results are visualized using matplotlib.
-
Error Handling:
- Error messages will be displayed in case of invalid inputs or issues with file loading.
This project is licensed under the MIT License. See the LICENSE file for details.