幅度和傅立葉相位變換F被定義爲:入門從相位和幅度傅立葉變換 - Matlab的
Mag = sqrt(Real(F)^2 + Imaginary(F)^2)
和
Phase = arctan(Imaginary(F)/Real(F))
伊夫試圖寫MATLAB代碼,取入一個灰度圖像矩陣,在矩陣上執行fft2(),然後計算變換的幅度和相位。然後我希望計算傅里葉變換的虛部和實部。
Real = Mag/sqrt(1 + tan(Phase)^2)
和
Imaginary = Real*tan(Phase)
,最後組合和反FFT2:
F = Real + i*Imaginary
image = ifft2(F)
我希望看到相同的圖像,因爲這是由前兩個方程重新排列成完成輸入,但我得到垃圾。我的數學錯了嗎?我的MATLAB M文件的代碼如下:
function y = forwardBackwardFFT(image)
F = fft2(image);
mag = sqrt(real(F).^2 + imag(F).^2);
phase = atan(imag(F)./real(F));
re = sqrt((mag.^2)./(1 + tan(phase).^2));
im = re.*tan(phase);
F = re + i*im;
f = ifft2(F);
subplot(1,2,1);
imshow(image);
Title('Original Image');
subplot(1,2,2);
imshow(f);
Title('Image after forward and backward FFT');
y = f;
感謝很多:)
啊謝謝一噸!棒極了。 atan(im./re)和atan2(im,re)之間最大的區別是什麼?昨天我嘗試了同樣類型的東西,從mag和cos和罪惡中獲得重新和im,但它仍然給我垃圾。與你的建議atan2(),它的作品。感謝一噸雖然:) –
@Dave:見http://en.wikipedia.org/wiki/Atan2#Motivation。 –
@nibot不好意思的男人,還沒來過這裏。只是選擇它作爲接受的答案 –