Fourier analysis provides a powerful framework for decomposing digital images into their constituent spatial frequency components. This technique enables precise manipulation and interpretation of image structure beyond what is visible in the pixel domain.
Core Concepts
The two-dimensional discrete Fourier transform (2D-DFT) maps an M × N grayscale image f(x, y) into a complex-valued frequency spectrum F(u, v), where:
- Magnitude spectrum: |F(u, v)| reflects energy distribution across spatial frequencies.
- Phase spectrum: ∠F(u, v) encodes positional relationships between frequency components—critical for structural fidelity.
The inverse DFT reconstructs the original spatial-domain image from its spectral representation. While magnitude dominates perceptual brightness, phase information governs edge localization and global shape perception.
Spectral Centering Strategy
By default, the zero-frequency (DC) component appears at the top-left corner of the DFT output. For intuitive visualization and symmetric filtering, spectral centering relocates DC to the array center. This implementation applies quadrant swapping:
- Divide the spectrum into four quadrants: top-left (Q1), top-right (Q2), bottom-left (Q3), bottom-right (Q4).
- Swap Q1 ↔ Q4 and Q2 ↔ Q3 using matrix indexing rather than iterative loops—improving both readability and computational efficiency.
Implementation Highlights
The following MATLAB script demonstrates three key operations on grayscale imagery:
clear; clc; close all;
% Load and preprocess reference image
I = im2double(rgb2gray(imread('lena.jpg')));
figure('Position', [100, 100, 1200, 800]);
% Task 1: Forward/inverse transform verification
subplot(3,4,1), imshow(I), title('Original Image');
F = fft2(I);
subplot(3,4,2), imshow(log(1 + abs(F)), []), title('Raw Spectrum');
subplot(3,4,3), imshow(log(1 + abs(fftshift(F))), []), title('Centered Spectrum');
I_recon = real(ifft2(F));
subplot(3,4,4), imshow(I_recon, []), title('Reconstructed Image');
% Task 2: Synthetic pattern analysis
P = zeros(1000); P(350:649, 475:524) = 1;
subplot(3,4,5), imshow(P), title('Rectangular Pattern');
F_p = fft2(P);
subplot(3,4,6), imshow(log(1 + abs(F_p)), []), title('Pattern Spectrum');
subplot(3,4,7), imshow(abs(fftshift(F_p)), []), title('Centered Magnitude');
subplot(3,4,8), imshow(log(1 + abs(fftshift(F_p))), []), title('Log-Centered Spectrum');
% Task 3: Phase-only reconstruction
F_i = fft2(I);
phase_only = exp(1i * angle(F_i));
I_phase = real(ifft2(phase_only));
subplot(3,4,9), imshow(I), title('Original');
subplot(3,4,10), imshow(angle(F_i), [-pi pi]), title('Phase Map');
subplot(3,4,11), imshow(I_phase, []), title('Phase-Only Reconstruction');
subplot(3,4,12), imshow(mat2gray(I_phase)), title('Normalized Phase-Only Output');
Optimized Centering Function
Replacing the original loop-based Centralization function with MATLAB’s built-in fftshift eliminates manual index arithmetic and reduces error potential:
function centered = spectral_center(F)
centered = fftshift(F);
end
Interpretation Guidelines
- Task 1: The reconstructed image matches the input within numerical precision, confirming invertibility of the DFT pair.
- Task 2: The rectangular region produces a sinc-like spectrum; centering reveals symmetry and isolatse low-frequency concentration near the origin.
- Task 3: Phase-only reconstruction preserves coarse geometry and edge continuity but suppresses texture and intensity gradients—highlighting phase’s dominance in structural encoding.