低通高斯滤波器,具有指定的截止频率 [英] Low pass gaussian filter with a specified cut off frequency

查看:495
本文介绍了低通高斯滤波器,具有指定的截止频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩混合图像,并希望使用高斯滤镜低通滤波图像。但是,为了制作混合图像,应该在2个图像上使用2个滤镜,这些滤镜与不同的截止频率组合。

I'm playing around with hybrid images, and wanted to use a gaussian filter to low pass filter an image. However, to make hybrid images, 2 filters are supposed to be used on the 2 images being combined with different cut off frequencies.

fspecial( )允许我们在使用它来制作高斯滤波器时指定截止频率? (我知道我们可以指定滤波器大小和sigma,并且sigma和截止频率之间存在某种关系)。如果我们只能使用sigma指定截止频率,那么我需要设置什么sigma来获得0.2 Hz的截止频率。

Does fspecial() allow us to specify cut off frequencies when we employ it to make a gaussian filter? (I know that we can specify the filter size and sigma and that there is some relation between sigma and cut off frequency). If we can only specify cut off frequencies using sigma, then what sigma would I need to set to get a cut off frequency of say 0.2 Hz.

推荐答案

我将首先回答有关1D的问题,其余的将会跟进。它可能看起来很微不足道,但请耐心等待一段时间。让我们假设以下代码:

I'll first answer regarding 1D and the rest will follow. It may look trivial, but bear with me for a while. Lets assume the following code:

t=linspace(0,20,2^10); %time vector in seconds
w=0.2; %in Hz
signal=cos(2*pi*w*t)+rand(1,length(t))-0.5; % signal in seconds
dt=t(2)-t(1) ;
N=length(signal);
df=1/(N*dt);    % the frequency resolution (df=1/max_T)
if mod(N,2)==0
    f_vec= df*((1:N)-1-N/2);  % for EVEN length vectors
else
    f_vec= df*((1:N)-0.5-N/2); 
end

因此,我们创建了一个特定频率的噪声信号。 f_vec是从f = [ - f_max,-f_max + df,...,0,...,f_max]延伸的频率向量,其中f_max = 1 /(2 * dt)。如果我们现在设计一个1D高斯滤波器(在傅立叶空间中)如下:

So, we have created a noisy signal of a specific frequency. f_vec is the frequency vector that stretches from f =[-f_max,-f_max+df,...,0,...,f_max], with f_max=1/(2*dt). If we now design a 1D Gaussian filter (in the fourier space) as follows:

f_vec0=0;
sigma=1;
filter=exp( -(f_vec-f_vec0).^2./(2*sigma^2)); 

然后过滤傅立叶doamin:

and then filtering in the fourier doamin:

f_signal=fftshift(fft(signal));
filt_signal=fftshift(ifft(f_signal.*filter));

因此,从我们应用的过滤器,sigma = 1表示截止频率(我决定了)是滤波器最大值的1%(即1))大约为3 Hz:

So, from the filter we applied, sigma=1 means the the cut off frequency (that I decided is 1% of the filter's maximum (which is 1)) is approximately at 3 Hz:

 cutoff_freq=f_vec(find(filter>=0.01,1,'last'))

将此视为2D是微不足道的,只需要小心与单位。对于图像,有像素作为位置单位,1 /像素作为空间频率。 fspecial函数生成预定义过滤器的2D矩阵。 fspecial的用法通常是这样的:

Taking this to 2D is trivial, just be careful with units. For images, there are pixels as the position unit, and 1/pixels as the spacial frequency. The fspecial function generates a 2D matrix of a predefined filter. The usage of fspecial is usually like this:

PSF = fspecial('gaussian',hsize,sigma);
Blurred = imfilter(Image,PSF,'symmetric','conv');

使用卷积就像在傅立叶域中相乘一样。傅立叶域中的sigma与位置域的1 / sigma等成比例...

Using convolution is just like multiplying in the Fourier domain. The sigma in the Fourier domain is proportional to 1/sigma of the position domain, etc...

这篇关于低通高斯滤波器,具有指定的截止频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆