我想在MATLAB中反转图像的傅立叶变换,但是结果不是原始图像(应该是原始图像)。显然有一些实现细节,我不知道这是导致问题的原因。这是代码:
img = imread('img.jpg'); fft = fft2(img); inv = ifft2(fft); imshow(inv);
回答:
由于
fft2和
ifft2都以
double精度或
single精度执行计算,因此在由fft2处理之前,
图像数据 (很可能为
uint8类型)将首先转换为double类型。因此,您将必须使用函数
uint8将输出图像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中。
更多&回答...