【问题标题】:How can I restore my image back from the Fourier Spectrum如何从傅里叶光谱中恢复我的图像
【发布时间】:2019-04-10 03:52:42
【问题描述】:

我拍摄了以下图片: PandaNoise.bmp 并试图通过关注其傅里叶频谱来消除周期性噪声。注释行是我不确定的行。我无法将其恢复到图像平面。我在这里做错了什么?

panda = imread('PandaNoise.bmp');
fpanda = fft2(panda); % 2d fast fourier transform
fpanda = fftshift(fpanda); % center FFT
fpanda = abs(fpanda); % get magnitude
fpanda = log(1 + fpanda); % use log to expand range of dark pixels into bright region
fpanda = mat2gray(fpanda); % scale image from 0 to 1
figure; imshow(fpanda,[]); % show the picture
zpanda = fpanda;
zpanda(fpanda<0.5)=0;
zpanda(fpanda>0.5)=1;
%img = ifft2(zpanda);
%img = ifftshift(img);
%img = exp(1-img);
%img = abs(img);

【问题讨论】:

  • abslog 非常适合显示,但您应该将逆变换应用于您在执行这些操作之前拥有的数据。 abs 丢弃了相位信息,log 还以使逆变换毫无意义的方式更改数据。
  • 但是我怎样才能使用复数矩阵,因为这是我使用 FFT 后得到的,而不使用 abs() ?
  • 你仍然可以这样做。 Cris 只是说你不应该在反向 FFT 的路径上这样做。

标签: matlab image-processing filtering fft


【解决方案1】:

这是一个如何使用复数傅立叶变换的示例。我们可以取对数模数显示,但不要改变原来的傅里叶变换矩阵,因为我们用abs丢掉的相位信息非常重要。

% Load data
panda = imread('https://i.stack.imgur.com/9SlW5.png');
panda = im2double(panda);

% Forward transform
fpanda = fft2(panda);

% Prepare FT for display -- don't change fpanda!
fd = fftshift(fpanda);
fd = log(1 + abs(fd));
figure; imshow(fd,[]); % show the picture
% From here we learn that we should keep the central 1/5th along both axes

% Low-pass filter
sz = size(fpanda);
center = floor(sz/2)+1;
half_width = ceil(sz/10)-1;
filter = zeros(sz);
filter(center(1)+(-half_width(1):half_width(1)),...
       center(2)+(-half_width(2):half_width(2))) = 1;
filter = ifftshift(filter); % The origin should be on the top-left, like that of fpanda.
fpanda = fpanda .* filter;

% Inverse transform
newpanda = ifft2(fpanda);
figure; imshow(newpanda);

在计算了ifft2 之后,如果我们正确设计了滤波器(即围绕原点完全对称),newpanda 应该是纯实值。任何仍然存在的虚构成分都应该是纯粹的数字错误。 MATLAB 将检测到ifft2 的输入是共轭对称的,并返回一个纯实数结果。 Octave 不会,您必须执行newpanda=real(newpanda) 以避免来自imshow 的警告。

【讨论】:

  • 太棒了!谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 1970-01-01
  • 2015-01-20
  • 2021-07-12
  • 1970-01-01
  • 2014-05-26
相关资源
最近更新 更多