为什么傅里叶逆变换不能给出正确的结果?
我想在 MATLAB 中反转图像的傅立叶变换,但结果不是原始图像(应有的样子)。显然有一些我不知道的实现细节导致了这个问题。这是代码:
img = imread('img.jpg');
fft = fft2(img);
inv = ifft2(fft);
imshow(inv);
I want to invert the Fourier transform of an image in MATLAB, but the result is not the original image (as it should be). There is obviously some implementation detail that I don't know about that's causing the issue. Here's the code:
img = imread('img.jpg');
fft = fft2(img);
inv = ifft2(fft);
imshow(inv);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自
fft2
和ifft2
都在double
或单
精度,您的图像数据(可能是uint8
) 在被fft2< 处理之前首先转换为
double
类型/代码>。因此,您必须使用函数uint8
来恢复原始图像:注意: 作为一个额外的提示,我会避免命名你的变量
fft
和inv
因为具有这些名称的函数已存在于 MATLAB 中。Since
fft2
andifft2
both perform calculations in eitherdouble
orsingle
precision, your image data (which is likely of typeuint8
) gets converted to typedouble
first before being processed byfft2
. You will therefore have to convert your output imageinv
back to an unsigned 8-bit integer using the functionuint8
to recover the original image:NOTE: As an additional tip, I would avoid naming your variables
fft
andinv
since functions with those names already exist in MATLAB.另外,如果您尝试对彩色(24 位)图像进行 FFT,请注意 imread() 将返回 M x N x 3 数组。因此,您应该对每个 R/G/B 通道分别执行 FFT。
请参阅此了解详细信息。
Also if you are trying to do FFT on color (24-bit) image - note that imread() will return M x N x 3 array. So you should perform FFT on each R/G/B channel separately.
See this for detail.