我拍摄了以下图像: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);
下面是如何使用复数傅立叶变换的示例。我们可以用对数模来显示,但不改变原始的傅立叶变换矩阵,因为我们用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
的警告。