MATLAB中的高斯平滑 [英] Gaussian smoothing in MATLAB

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

问题描述

对于带有一些嘈杂图像的 m x n 元素数组,我想执行高斯平滑。我如何在 MATLAB 中做到这一点?



<我已经读过数学涉及用一定规模的内核来平滑所有内容,但我不知道如何在MATLAB中做到这一点。

解决方案

希望你有图像处理工具箱。如果是这样,那么您可以使用 fspecial function <创建高斯滤镜/ a>像这样:

  myfilter = fspecial('gaussian',[3 3],0.5); 

我在这里使用了hsize([3 3])和sigma(0.5)的默认值,但你可能想和他们一起玩。 hsize只是滤波器的大小,在这种情况下它是一个3 x 3矩阵。 Sigma是高斯函数的sigma(参见fspecial函数页面的底部)。



现在你可以使用 imfilter 来过滤您的图片:

  myfilteredimage = imfilter(unfilteredimage,myfilter,'replicate'); 

这里我简单地传入了unfilteredimage,过滤器和一个参数,说明过滤器应该如何处理边界。在这种情况下,我选择了复制,它将数组边界外的输入数组值设置为最接近的数组边界值,但您可以尝试其他一些值(或者不使用该选项将图像值之外的所有值设置为0)。


For an m x n array of elements with some noisy images, I want to perform Gaussian smoothing. How do I do that in MATLAB?

I've read the math involves smoothing everything with a kernel at a certain scale, but I have no idea how to do this in MATLAB.

解决方案

Hopefully, you have the Image Processing toolbox. If so, then you can create a Gaussian filter with the fspecial function like so:

myfilter = fspecial('gaussian',[3 3], 0.5);

I have used the default values for hsize ([3 3]) and sigma (0.5) here, but you might want to play around with them. hsize is just the size of the filter, in this case it is a 3 x 3 matrix. Sigma is the sigma of the gaussian function (see the bottom of the fspecial function page).

Now you can use imfilter to filter your image:

myfilteredimage = imfilter(unfilteredimage, myfilter, 'replicate');

here I have simply passed in the unfilteredimage, the filter, and a parameter that says how the filter should handle the boundaries. In this case, I've chosen replicate which sets input array values outside the bounds of the array to the nearest array border value, but you can try some other values (or leaving off that option sets all outside of image values to 0).

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

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