Performing DFT and DCT Transformations on an Image with MATLAB

Resource Overview

Implementation of Discrete Fourier Transform (DFT) and Discrete Cosine Transform (DCT) on images using MATLAB, with comparative analysis of image reconstruction using only 20 DCT coefficients versus the original image.

Detailed Documentation

This tutorial demonstrates how to perform Discrete Fourier Transform (DFT) and Discrete Cosine Transform (DCT) on digital images using MATLAB. The implementation involves loading an image, converting it to grayscale for simplified processing, and applying MATLAB's built-in functions: fft2() for 2D DFT and dct2() for 2D DCT transformations. The core algorithm focuses on coefficient retention strategy where we preserve only the top 20 magnitude coefficients in the DCT domain, setting all others to zero before performing inverse transformation using idct2(). This approach allows us to quantify reconstruction quality by calculating Mean Squared Error (MSE) and Peak Signal-to-Noise Ratio (PSNR) between the reconstructed and original images. Key implementation steps include: 1. Image preprocessing and normalization 2. Frequency domain transformation using fftshift() for better visualization 3. Coefficient thresholding and selective reconstruction 4. Quantitative and visual comparison of image quality degradation The comparison reveals how DCT's energy compaction property enables reasonable reconstruction with minimal coefficients, demonstrating its superiority for image compression applications compared to DFT.