如何在Matlab中绘制2D FFT?

Ben*_*Uri 39 matlab plot fft image-processing

我使用fft2来计算MATLAB中灰度图像的傅里叶变换.

绘制结果大小的常用方法是什么?

Ben*_*Uri 54

假设这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
Run Code Online (Sandbox Code Playgroud)

  • +1.您可以添加注释,说明您使用日志的原因(F + 1)而不是日志(F) - (由于log(0)未定义的值) (7认同)

Nas*_*ser 23

以下是我的HOW TO 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');
Run Code Online (Sandbox Code Playgroud)

这给出了图像的幅度谱和相位谱.我使用了彩色图像,但您也可以轻松调整它以使用灰色图像.

PS.我刚注意到在Matlab 2012a上面不再包含上面的图像了.所以,只需用上面的第一行替换即可

img = imread('ngc6543a.jpg');
Run Code Online (Sandbox Code Playgroud)

它会起作用.我使用旧版本的Matlab来制作上面的例子,然后在这里复制它.

关于缩放因子

当我们绘制2D傅里叶变换幅度时,我们需要使用对数变换来缩放像素值,以将暗像素的范围扩展到明亮区域,以便我们可以更好地看到变换.我们c在等式中使用一个值

s = c log(1+r) 
Run Code Online (Sandbox Code Playgroud)

我知道,没有任何已知的方法来预测这种规模.只需要尝试不同的值就可以了.我100在上面的例子中使用过.

在此输入图像描述

  • 你在空间和频域应用`fftshift`.那个...不能对,不是吗? (4认同)