为什么这个逆傅立叶变换不能给出正确的结果呢? [英] Why isn't this inverse Fourier transform giving the correct results?

查看:97
本文介绍了为什么这个逆傅立叶变换不能给出正确的结果呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);


推荐答案

FFT2 IFFT2 都只支持 double 单个 图像数据(可能类型为 uint8 )转换为类型 double 首先在FFT2处理之前。因此,您必须使用函数 inv 转换回无符号的8位整数/techdoc/ref/uint8.htmlrel =noreferrer> UINT8 恢复原始图像:

Since FFT2 and IFFT2 both only support inputs of type double and single, your image data (which is likely of type uint8) gets converted to type double first before being processed by FFT2. You will therefore have to convert your output image inv back to an unsigned 8-bit integer using the function UINT8 to recover the original image:

>> 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中。

NOTE: As an additional tip, I would avoid naming your variables fft and inv since functions with those names already exist in MATLAB.

这篇关于为什么这个逆傅立叶变换不能给出正确的结果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆