Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我想在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中。 更多&回答... |
![]() |
![]() |