我正在使用MATLAB中的fft2函数计算灰度图像的傅里叶变换。
常用的绘制结果幅值的方法是什么?
我正在使用MATLAB中的fft2函数计算灰度图像的傅里叶变换。
常用的绘制结果幅值的方法是什么?
I
为输入图像,F
为其傅里叶变换(即F = fft2(I)
),则可以使用以下代码:F = fftshift(F); % Center FFT
F = abs(F); % Get the magnitude
F = log(F+1); % Use log, for perceptual scaling, and +1 since log(0) is undefined
F = mat2gray(F); % Use mat2gray to scale the image between 0 and 1
imshow(F,[]); % Display the result
这是来自我的Matlab教程页面的例子:
close all; clear all;
img = imread('lena.tif','tif');
imagesc(img)
img = fftshift(img(:,:,2));
F = fft2(img);
figure;
imagesc(100*log(1+abs(fftshift(F)))); colormap(gray);
title('magnitude spectrum');
figure;
imagesc(angle(F)); colormap(gray);
title('phase spectrum');
这显示了图像的幅度谱和相位谱。我使用了一张彩色图像,但您也可以轻松调整为灰度图像。
附:我刚注意到在Matlab 2012a中上述图像已不再包含。所以,只需将上面的第一行替换为
img = imread('ngc6543a.jpg');
它会起作用。我使用了较旧版本的Matlab来制作上面的例子,只是将其复制到这里。
关于缩放因子
当我们绘制2D Fourier变换幅度时,需要使用对数变换来缩放像素值,以将暗像素的范围扩展到亮区域,以便更好地观察变换。 我们在等式中使用 c 值。
s = c log(1+r)
据我所知,没有已知的方法可以预先确定这个比例尺。只需要尝试不同的值,找到自己喜欢的即可。在上面的示例中,我使用了100
。
fftshift
。这...不太对吧? - geometrian