简体   繁体   English

傅立叶逆变换功能给出错误结果

[英]Inverse Fourier Transform function gives wrong result

I am implementing a code for image enhancement and to apply Fourier and inverse Fourier transform I am using the code below but in result it gives black image. 我正在实现用于图像增强的代码,并应用傅里叶和傅里叶逆变换。我正在使用下面的代码,但是结果是黑色图像。

F = fft2(image); 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
Y = ifft2(F);
subplot(1,1,1);
imshow(Y,[]); % Display the result

You try to image the inverse FFT of a matrix which is pure real (and positive), abs(F) . 您尝试对矩阵的逆FFT进行成像,该矩阵是纯实数(和正数) abs(F) The inverse FT of that is a complex one, and since you lose the phase of the original FT, you will get strange result (almost black image, with eventually the first pixel white...). 它的逆FT是一个复杂的FT,并且由于您失去了原始FT的相位,您将得到奇怪的结果(几乎是黑色图像,最终第一个像素是白色...)。

Second error, you shift the fft to make some computations, but you don't inverse the shift before 第二个错误,您将fft进行了一些计算,但是在执行之前您并未逆向进行移位

For what you want, you have to keep the phase of the FFT: 对于所需的内容,必须保留FFT的相位:

F = fft2(image); F = fftshift(F); % Center FFT
Fp = angle(F); % Get the phase
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
Y = real(ifft2(ifftshift(F.*exp(1i*Fp))));
subplot(1,1,1);
imshow(Y,[]); % Display the result

Note: you need to take the real part of the inverse FFT since Matlab creates automatically a complex array as output of a FT (direct or inverse), even if it is a real output. 注意:由于Matlab会自动创建一个复杂的数组作为FT的输出(正向或反向),因此即使它是实际输出,也需要考虑逆FFT的实部。 You can check this if you see the value of max(abs(imag(Y(:)))) , 6e-11 on my computer. 如果在我的计算机上看到max(abs(imag(Y(:)))) 6e-11的值,则可以进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM