加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

高斯平滑滤波器的模板系数(zz)和oversampling

(2016-03-04 16:31:49)
分类: computerVision

http://blog.csdn.net/hhygcy/article/details/4329056

http://blog.sina.com.cn/s/blog_afe2af380101blh0.html

http://www.360doc.com/content/12/0921/17/10724725_237428926.shtml

http://www.ruanyifeng.com/blog/2012/11/gaussian_blur.html

http://blog.csdn.net/zssureqh/article/details/7631056

http://blog.csdn.net/l_inyi/article/details/8915116

http://blog.sina.com.cn/s/blog_80ce3a550102viex.html



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

http://p.blog.csdn.net/images/p_blog_csdn_net/hhygcy/EntryImages/20090707/kernel1.png

http://p.blog.csdn.net/images/p_blog_csdn_net/hhygcy/EntryImages/20090707/kernel2.png

  一个标准差为1.4的高斯5x5的卷积核:   
    
       
    12     
   12   15  12    
    12     
             
    
  最后乘以比例系数   1/115  

其实就是直接设置方差来根据高斯分布计算NXN的系数再进行整数化就可以。

但是这个5x5的模板需要/273,硬件实现不友好,因此需要是2的指数。


一、高斯模糊的原理

所谓"模糊",可以理解成每一个像素都取周边像素的平均值。

http://image.beekka.com/blog/201211/bg2012111403.png

上图中,2是中间点,周边点都是1。

http://image.beekka.com/blog/201211/bg2012111404.png

"中间点"取"周围点"的平均值,就会变成1。在数值上,这是一种"平滑化"。在图形上,就相当于产生"模糊"效果,"中间点"失去细节。

http://image.beekka.com/blog/201211/bg2012111405.jpg

显然,计算平均值时,取值范围越大,"模糊效果"越强烈。

http://image.beekka.com/blog/201211/bg2012111406.jpg

上面分别是原图、模糊半径3像素、模糊半径10像素的效果。模糊半径越大,图像就越模糊。从数值角度看,就是数值越平滑。

接下来的问题就是,既然每个点都要取周边像素的平均值,那么应该如何分配权重呢?

如果使用简单平均,显然不是很合理,因为图像都是连续的,越靠近的点关系越密切,越远离的点关系越疏远。因此,加权平均更合理,距离越近的点权重越大,距离越远的点权重越小。

二、正态分布的权重

正态分布显然是一种可取的权重分配模式。

http://image.beekka.com/blog/201211/bg2012111407.png

在图形上,正态分布是一种钟形曲线,越接近中心,取值越大,越远离中心,取值越小。

计算平均值的时候,我们只需要将"中心点"作为原点,其他点按照其在正态曲线上的位置,分配权重,就可以得到一个加权平均值。

三、高斯函数

上面的正态分布是一维的,图像都是二维的,所以我们需要二维的正态分布。

http://image.beekka.com/blog/201211/bg2012110708.png

正态分布的密度函数叫做"高斯函数"(Gaussian function)。它的一维形式是:

高斯平滑滤波器的模板系数(zz)和oversampling

其中,μ是x的均值,σ是x的方差。因为计算平均值的时候,中心点就是原点,所以μ等于0。

高斯平滑滤波器的模板系数(zz)和oversampling

根据一维高斯函数,可以推导得到二维高斯函数:

高斯平滑滤波器的模板系数(zz)和oversampling

有了这个函数 ,就可以计算每个点的权重了。

四、权重矩阵

假定中心点的坐标是(0,0),那么距离它最近的8个点的坐标如下:

http://image.beekka.com/blog/201211/bg2012111410.png

更远的点以此类推。

为了计算权重矩阵,需要设定σ的值。假定σ=1.5,则模糊半径为1的权重矩阵如下:

http://image.beekka.com/blog/201211/bg2012111411.png

这9个点的权重总和等于0.4787147,如果只计算这9个点的加权平均,还必须让它们的权重之和等于1,因此上面9个值还要分别除以0.4787147,得到最终的权重矩阵。

http://image.beekka.com/blog/201211/bg2012111412.png

五、计算高斯模糊

有了权重矩阵,就可以计算高斯模糊的值了。

假设现有9个像素点,灰度值(0-255)如下:

http://image.beekka.com/blog/201211/bg2012111413.png

每个点乘以自己的权重值:

http://image.beekka.com/blog/201211/bg2012111414.png

得到

http://image.beekka.com/blog/201211/bg2012111416.png

将这9个值加起来,就是中心点的高斯模糊的值。

对所有点重复这个过程,就得到了高斯模糊后的图像。如果原图是彩色图片,可以对RGB三个通道分别做高斯模糊。

六、边界点的处理

如果一个点处于边界,周边没有足够的点,怎么办?

一个变通方法,就是把已有的点拷贝到另一面的对应位置,模拟出完整的矩阵。





Oversampling and undersampling in data analysis are techniques used to adjust the class distribution of a data set (i.e. the ratio between the different classes/categories represented).

Oversampling and undersampling are opposite and roughly equivalent techniques. They both involve using a bias to select more samples from one class than from another.

The usual reason for oversampling is to correct for a bias in the original dataset. One scenario where it is useful is when training a classifier using labelled training data from a biased source, since labelled training data is valuable but often comes from un-representative sources.

For example, suppose we have a sample of 1000 people of which 66.7% are male (perhaps the sample was collected at a football match). We know the general population is 50% female, and we may wish to adjust our dataset to represent this. Simple oversampling will select each female example twice, and this copying will produce a balanced dataset of 1333 samples with 50% female. Simple undersampling will drop some of the male samples at random to give a balanced dataset of 667 samples, again with 50% female.[clarification needed]

There are also more complex oversampling techniques, including the creation of artificial data points.

0

阅读 收藏 喜欢 打印举报/Report
前一篇:照度和流明
后一篇:标准光源箱
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有