2012-11-25 167 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