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

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

问题描述

我有一个 n 维向量(1xn 数据集,它不是图像数据),我想对其应用高斯滤波器.我有 Image Processing Toolkit 和其他一些(询问您是否需要列表).

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).

大概我可以使 fspecial 函数的 hsize 参数类似于 [1 n].作为下一步,我仍然可以使用 imfilter 将其应用于我的向量,还是应该使用其他东西?

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?

我已经看过很多关于如何在 Matlab 中将高斯滤波器应用于二维图像数据的示例,但我对 Matlab 作为平台还是比较陌生,所以一个示例会非常好.

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.

注意:我目前无法尝试看看会发生什么(目前不在安装了 Matlab 的机器上),否则我会先尝试一下,只询问我是否在使用 fspecialimfilter.

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.

推荐答案

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

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

为了应用它,你可以使用 filter:

and in order to apply it you can use filter:

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

并且不要忘记滤波器有延迟,这意味着与输入信号相比,滤波后的信号会发生偏移.由于此过滤器是对称的,您可以通过使用 conv 而不是 filter 获得非移位输出,并使用 same 选项:

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天全站免登陆