高斯滤波在Matlab中的矢量 [英] Gaussian Filter on a vector in Matlab

查看:253
本文介绍了高斯滤波在Matlab中的矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个n维向量(1xn数据集,它不是图像数据),我想应用一个高斯滤波器。我有图像处理工具包和其他一些(询问你是否需要一个列表)。

假设我可以使 hsize > > fspecial 函数的参数,类似于 [1 n]
我是否仍然可以使用 imfilter 将其应用到我的向量中,或者我应该使用其他的方法吗?

我已经看到了很多关于如何在Matlab中将高斯滤波应用于二维图像数据的例子,但对于Matlab作为一个平台,我还是比较新的,所以一个例子会非常好。 / p>

注意:我目前还没有试过,看看会发生什么(当前没有安装Matlab的机器上),否则我会先试一下并只问我是否遇到问题,使用 fspecial imfilter

解决方案

为什么不自己创建高斯过滤器?你可以看看 fspecial (或其他任何高斯定义)的公式:

  sigma = 5; 
sz = 30; %gaussFilter向量的长度
x = linspace(-sz / 2,sz / 2,sz);
gaussFilter = exp(-x。^ 2 /(2 * sigma ^ 2));
gaussFilter = gaussFilter / sum(gaussFilter); %normalize

为了应用它,您可以使用 filter

  y = rand(500,1); 
yfilt = filter(gaussFilter,1,y);

不要忘记滤波器有延迟,这意味着滤波后的信号相对于输入信号。由于此过滤器是对称的,因此可以通过使用 conv 而不是 filter 来获得未转换的输出,并使用相同选项:

  yfilt = conv(y,gaussFilter, ); 


I have a n-dimensional vector (1xn dataset, and it is not image data), and I want to apply a Gaussian filter to it. I have the Image Processing Toolkit, and a few others (ask if you need a list).

Presumably I can make the hsize parameter of the fspecial function something like [1 n]. Can I still use imfilter to apply it to my vector as the next step, or should I be using something else?

I've seen quite a few examples on how to apply a Gaussian filter to two dimensional image data in Matlab, but I'm still relatively new to Matlab as a platform so an example would be really good.

Note: I'm not currently in a position to just try it and see what happens (not currently on a machine with Matlab installed), otherwise I would have tried it first and only asked if I ran into problems using fspecial and imfilter.

解决方案

Why not create the Gaussian filter yourself? You can look at the formula in fspecial (or any other definition of a Gaussian):

sigma = 5;
sz = 30;    % length of gaussFilter vector
x = linspace(-sz / 2, sz / 2, sz);
gaussFilter = exp(-x .^ 2 / (2 * sigma ^ 2));
gaussFilter = gaussFilter / sum (gaussFilter); % normalize

and in order to apply it you can use filter:

y = rand(500,1);
yfilt = filter (gaussFilter,1, y);

and don't forget the filter has latency, which means the filtered signal is shifted as compared to the input signal. Since this filter is symmetric, you can get a non-shifted output by using conv instead of filter, and use the same option:

yfilt = conv (y, gaussFilter, 'same');

这篇关于高斯滤波在Matlab中的矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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