2012-11-25 171 views

回答

51

假设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 
+6

+1。您可以添加注释,说明您为什么使用日志(F + 1)而不是日志(F) - (由于日志(0)未定义值) –

+0

@Andery谢谢,完成。 –

23

这里是我如何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'); 

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

ps。我只注意到在Matlab 2012a上面的图像不再包含在内。所以,只需将上面的第一行替换为

img = imread('ngc6543a.jpg'); 

它会工作。我使用了一个老版本的Matlab来制作上面的例子,并在这里复制它。

在缩放因子

当我们绘制2D傅里叶变换幅度,我们需要用数变换扩大暗像素到明亮区域的范围,所以我们可以更好地看到缩放像素值变换。我们的方程式

s = c log(1+r) 

有预借以了解物质这个规模,我知道没有已知的方法在使用c值。只需要 尝试不同的值,以得到你喜欢的。在上面的例子中我使用了100

enter image description here

+0

如果您使用imagesc(不设置c限制),那么对于您正在使用的常数c没有意义 –

+4

您正在空间和频域中应用'fftshift'。那个。 。 。不可能是正确的,不是? – imallett