高斯平滑滤波matlab,高斯平滑 高斯模糊 高斯滤波器 ( Gaussian Smoothing, Gaussian

本文介绍了高斯平滑、高斯模糊和高斯滤波器的概念,它们是带权的平均滤波器,通过高斯分布权重进行像素颜色的平滑处理。文中展示了不同大小的高斯模板对图像平滑的效果,并提供了5x5高斯滤波器的C++实现代码。尽管这种滤波器能够平滑图像,但并不擅长消除噪声。
摘要由CSDN通过智能技术生成

高斯平滑 高斯模糊 高斯滤波器 ( Gaussian Smoothing, Gaussian Blur, Gaussian Filter ) C++ 实现

发展到现在这个平滑算法的时候, 我已经完全不知道如何去命名这篇文章了, 只好罗列出一些关键字来方便搜索了.

在之前我们提到过了均值滤波器, 就是说某像素的颜色, 由以其为中心的九宫格的像素平均值来决定. 在这个基础上又发展成了带权的平均滤波器, 这里的高斯平滑或者说滤波器就是这样一种带权的平均滤波器. 那么这些权重如何分布呢? 我们先来看几个经典的模板例子:

e472107b89078bb6031a7755dcc4b5a3.png

e57064884c012ef275c520ed7d673504.png

尝试了使用这些滤波器对我们原来的图进行操作, 得到了这样的一组结果:

原图:

6e18e49b3ba2f688ec06d128b3e46598.png

3x3 高斯:

0d90abedaeec7353e3ae2998659810fe.png

5x5 高斯:

2c1673d55dc5c1b5ed363afd72612225.png

单纯从效果来看, 两个模板都起到了平滑的作用, 只是程度有深浅的区分. 那么从理论上来说为什么能起到平滑的作用呢? 很显然, 像素的颜色不仅由自身决定了, 同时有其周围的像素加权决定, 客观上减小了和周围像素的差异. 同时这些权重的设定满足了越近权重越大的规律. 从理论来讲, 这些权重的分布满足了著名的所谓高斯分布:

52bfb99993e7d028d69b2a6720da0332.gif   这就是1维的计算公式

2496e6115df126d929d16b2bfe739fd9.gif 这就是2维的计算公式

x, y表示的就是当前点到对应点的距离, 而那些具体的模板就是由这里公式中的一些特例计算而来. 需要说明的是不只有这么一些特例, 从wikipedia可以方便地找到那些复杂的模板比如像:

Sample Gaussian matrix

This is a sample matrix, produced by sampling the Gaussian filter kernel (with σ = 0.84089642) at the midpoints of each pixel and then normalising. Note that the center element (at [4, 4]) has the largest value, decreasing symmetrically as distance from the center increases.

0.00000067

0.00002292

0.00019117

0.00038771

0.00019117

0.00002292

0.00000067

0.00002292

0.00078633

0.00655965

0.01330373

0.00655965

0.00078633

0.00002292

0.00019117

0.00655965

0.05472157

0.11098164

0.05472157

0.00655965

0.00019117

0.00038771

0.01330373

0.11098164

0.22508352

0.11098164

0.01330373

0.00038771

0.00019117

0.00655965

0.05472157

0.11098164

0.05472157

0.00655965

0.00019117

0.00002292

0.00078633

0.00655965

0.01330373

0.00655965

0.00078633

0.00002292

0.00000067

0.00002292

0.00019117

0.00038771

0.00019117

0.00002292

0.00000067

是不是看到就头大了:) 不过没关系, 对于一般的应用来说, 前面的例子已经可以完成任务了.  代码的话我们还是给一份5x5的example:

/**

** method to remove noise from the corrupted image by gaussian filter value

* @param corrupted input grayscale binary array with corrupted info

* @param smooth output data for smooth result,

the memory need to be allocated outside of the function

* @param width width of the input grayscale image

* @param height height of the input grayscale image

*/

voidgaussianFilter2 (unsignedchar* corrupted, unsignedchar* smooth

,intwidth,intheight)

{

inttemplates[25] = { 1, 4, 7, 4, 1,

4, 16, 26, 16, 4,

7, 26, 41, 26, 7,

4, 16, 26, 16, 4,

1, 4, 7, 4, 1 };

memcpy ( smooth, corrupted, width*height*sizeof(unsignedchar) );

for(intj=2;j

{

for(inti=2;i

{

intsum = 0;

intindex = 0;

for(intm=j-2; m

{

for(intn=i-2; n

{

sum += corrupted [ m*width + n] * templates[index++] ;

}

}

sum /= 273;

if(sum > 255)

sum = 255;

smooth [ j*width+i ] = sum;

}

}

}

附带说一些,很明显,和均值滤波器类似, 这个滤波器没有消除校验噪声的作用.

(hhygcy)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值