簡體   English   中英

matlab代碼:傅立葉域中的高斯模糊

[英]matlab code: Gaussian blurring in fourier domain

我正在看一些執行圖像模糊的代碼。 但是,我無法理解代碼,我想知道是否有人可以幫助我理解代碼的作用。

這里變量“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應用於尚未進入傅立葉域的圖像意味着什么。 所以,我可以告訴它是沿着每個軸進行傅立葉變換,但為什么它在前后進行了一次移位?

代碼如下:

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是否是高斯卷積核的傅立葉變換,或者至少無法從代碼中告訴它。

所以,我對如何實現高斯模糊感到有點困惑。 任何幫助理解此代碼將不勝感激。

你是正確的,在這段代碼中沒有高斯的FFT,但要記住(或學習)的事情是the Fourier space representation of a Gaussian is also a Gaussian ,只是具有倒數標准偏差。 編寫此代碼的人可能知道這一點,或者他們只是忘了並且很幸運。

請參閱高斯窗口和傅里葉變換的gausswin文檔部分。 文檔中壓縮版的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的輸出gausswin解釋為傅立葉空間而不執行和FFT,等同於在空間域中具有更大的西格瑪的高斯窗口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM