【问题标题】:matlab code: Gaussian blurring in fourier domainmatlab代码:傅里叶域中的高斯模糊
【发布时间】:2014-12-19 08:48:33
【问题描述】:

我正在查看一些执行图像模糊的代码。但是,我在理解代码时遇到了麻烦,我想知道是否有人可以帮助我理解代码的大致用途。

这里的变量“Iref”是一个图像。

Imin = min(Iref(:));

Iref_fft = Iref-Imin;
Iref_fft = fftshift(Iref_fft,1);
Iref_fft = fftshift(Iref_fft,2);

Iref_fft = fft(Iref_fft,[],1);
Iref_fft = fft(Iref_fft,[],2);

Iref_fft = fftshift(Iref_fft,1);
Iref_fft = fftshift(Iref_fft,2);

在这里,我已经对将 fftshift 应用于尚未在傅立叶域中的图像意味着什么感到困惑。所以,我可以说它正在沿每个轴进行傅立叶变换,但为什么它会在前后进行 fftshift?

代码如下:

Nx_r = 32;
Ny_r = 32;
sigma = 1.5;
wx      = reshape(gausswin(Nx_r,sigma), [1 Nx_r]);
wy      = reshape(gausswin(Ny_r,sigma), [Ny_r 1]);
wx_rep  = repmat(wx, [Ny_r 1]);
wy_rep  = repmat(wy, [1 Nx_r]);
Window  = wx_rep .* wy_rep;

xIndices = floor((Nx-Nx_r)/2)+1 : floor((Nx-Nx_r)/2)+Nx_r;
yIndices = floor((Ny-Ny_r)/2)+1 : floor((Ny-Ny_r)/2)+Ny_r;

Iref_blurred = zeros(Ny,Nx);
Iref_blurred(yIndices,xIndices,:) = Iref_fft(yIndices,xIndices) .* Window;
Iref_blurred = fftshift( ifft2( fftshift(Iref_blurred) ) );
Iref_blurred = abs(Iref_blurred)+Imin;

在随后的步骤中,我认为我们正在进行高斯模糊。但是,我认为内核也必须在傅立叶域中生成,然后我们才能像下面这样将它们相乘:

Iref_blurred(yIndices,xIndices,:) = Iref_fft(yIndices,xIndices) .* Window;

我不确定Window是高斯卷积核的傅立叶变换还是至少无法从代码中分辨出来。

所以,我有点困惑这是如何实现高斯模糊的。任何有助于理解此代码的帮助将不胜感激。

【问题讨论】:

    标签: matlab image-processing fft convolution


    【解决方案1】:

    您是正确的,此代码中没有进行高斯 FFT,但要记住(或学习)的是 the Fourier space representation of a Gaussian is also a Gaussian,只是具有倒数标准差。编写此代码的人可能知道这一点,或者他们只是忘记了并且很幸运。

    参见gausswin 文档中称为Gaussian Window and the Fourier 转换的部分。文档中gausswin 示例的精简版:

    N = 64; n = -(N-1)/2:(N-1)/2; alpha = 8;
    w = gausswin(N,alpha);
    nfft = 4*N; freq = -pi:2*pi/nfft:pi-pi/nfft;
    wdft = fftshift(fft(w,nfft));
    plot(n,w)
    hold on
    plot(freq/pi,abs(wdft) / 10,'r')
    title('Gaussian Window and FFT')
    legend({'win = gausswin(64,8)','0.1 * abs(FFT(win))'})
    

    因此,立即将gausswin 的输出解释为傅立叶空间,而不执行 FFT,相当于空间域中具有更大 sigma 的高斯窗口。

    【讨论】:

    • 感谢您的回答!所以,一个非常快速的问题。假设我的高斯核在空间域的标准差是2,那么傅里叶变换核的SD是0.5?
    • @Luca 我认为它与标准偏差成正比。或许可以在线或在 math.stackexchange.com 或 dsp.stackexchange.com 上查看数学详细信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多