clear, clc
I = imread('...');
F = fftshift(fft2(I)); % 对图像进行二维 DFT(fft2),并移至中心位置
magn = log(abs(F)); % 加 log 是便于显示,缩小值域
phase = log(angle(F)*180/pi); % 转换为度数
subplot(2, 2, 1), imshow(I, []), title('原图像')
subplot(2, 2, 2), imshow(log(F), []), title('图像频谱')
subplot(2, 2, 3), imshow(magn, []), title('图像幅度谱')
subplot(2, 2, 4), imshow(phase, []), title('图像相位谱')
- abs(F) == sqrt(real(F).^2 + imag(F).^2)
- angle(F) == log(imag(F)) == atan2(imag(F), real(F))