![]() |
为什么这种傅立叶逆变换不能给出正确的结果?
我想在MATLAB中反转图像的傅立叶变换,但是结果不是原始图像(应该是原始图像)。显然有一些实现细节,我不知道这是导致问题的原因。这是代码:
img = imread('img.jpg'); fft = fft2(img); inv = ifft2(fft); imshow(inv); [B]回答:[/B] 由于[URL="https://www.mathworks.com/help/matlab/ref/fft2.html"]fft2[/URL]和[URL="https://www.mathworks.com/help/matlab/ref/ifft2.html"]ifft2[/URL]都以[URL="https://www.mathworks.com/help/matlab/ref/double.html"]double[/URL]精度或[URL="https://www.mathworks.com/help/matlab/ref/single.html"]single[/URL]精度执行计算,因此在由fft2处理之前, [URL="https://www.mathworks.com/help/matlab/creating_plots/image-types.html"]图像数据[/URL] (很可能为[URL="https://www.mathworks.com/help/matlab/ref/uint8.html"]uint8[/URL]类型)将首先转换为double类型。因此,您将必须使用函数[URL="https://www.mathworks.com/help/matlab/ref/uint8.html"]uint8[/URL]将输出图像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! [B]注意:[/B]作为另一个提示,我将避免为变量fft和inv命名,因为具有这些名称的函数已经存在于MATLAB中。 [url=https://stackoverflow.com/questions/3729235]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:17。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.