登录论坛

查看完整版本 : 为什么这种傅立叶逆变换不能给出正确的结果?


poster
2019-12-10, 20:48
我想在MATLAB中反转图像的傅立叶变换,但是结果不是原始图像(应该是原始图像)。显然有一些实现细节,我不知道这是导致问题的原因。这是代码:

img = imread('img.jpg'); fft = fft2(img); inv = ifft2(fft); imshow(inv);

回答:

由于fft2 (https://www.mathworks.com/help/matlab/ref/fft2.html)和ifft2 (https://www.mathworks.com/help/matlab/ref/ifft2.html)都以double (https://www.mathworks.com/help/matlab/ref/double.html)精度或single (https://www.mathworks.com/help/matlab/ref/single.html)精度执行计算,因此在由fft2处理之前, 图像数据 (https://www.mathworks.com/help/matlab/creating_plots/image-types.html) (很可能为uint8 (https://www.mathworks.com/help/matlab/ref/uint8.html)类型)将首先转换为double类型。因此,您将必须使用函数uint8 (https://www.mathworks.com/help/matlab/ref/uint8.html)将输出图像inv转换回无符号的8位整数,以恢复原始图像:

>> img = imread('peppers.png'); % Load a sample image >> fft = fft2(img); % Get the Fourier transform >> inv = ifft2(fft); % Get the inverse Fourier transform >> inv = uint8(inv); % Convert to uint8 >> imshow(inv); % Show the image >> isequal(img, inv) % Test if inv matches the original image img ans = 1 % It does! 注意:作为另一个提示,我将避免为变量fft和inv命名,因为具有这些名称的函数已经存在于MATLAB中。



更多&回答... (https://stackoverflow.com/questions/3729235)