上一题下一题
跳转到
 
 
  世界如此多姿,发展如此迅速,窥一斑未必还能知全豹。但正如万花筒一样,每一个管窥都色彩斑斓。  
 
 
  知识通道 | 学习首页 | 教师首页 | PK首页 | 知识创造首页 | 企业首页 | 登录
 
本文对应知识领域
高斯平滑 高斯模糊 高斯滤波器 ( Gaussian Smoothing, Gaussian Blur, Gaussian Filter )
作者:未知 申领版权
2010年10月22日 共有 2209 次访问 【添加到收藏夹】 【我要附加题目
受欢迎度:

    发展到现在这个平滑算法的时候, 我已经完全不知道如何去命名这篇文章了, 只好罗列出一些关键字来方便搜索了.
    在之前我们提到过了均值滤波器, 就是说某像素的颜色, 由以其为中心的九宫格的像素平均值来决定. 在这个基础上又发展成了带权的平均滤波器, 这里的高斯平滑或者说滤波器就是这样一种带权的平均滤波器. 那么这些权重如何分布呢? 我们先来看几个经典的模板例子:
    
    
    尝试了使用这些滤波器对我们原来的图进行操作, 得到了这样的一组结果:
    原图:
    raw
    3x3 高斯:
    3x3
    5x5 高斯:
    5x5
    单纯从效果来看, 两个模板都起到了平滑的作用, 只是程度有深浅的区分. 那么从理论上来说为什么能起到平滑的作用呢? 很显然, 像素的颜色不仅由自身决定了, 同时有其周围的像素加权决定, 客观上减小了和周围像素的差异. 同时这些权重的设定满足了越近权重越大的规律. 从理论来讲, 这些权重的分布满足了著名的所谓高斯分布:
       这就是1维的计算公式
     这就是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:

    
  1. /** 
  2. ** method to remove noise from the corrupted image by gaussian filter value 
  3. * @param corrupted input grayscale binary array with corrupted info 
  4. * @param smooth output data for smooth result, the memory need to be allocated outside of the function 
  5. * @param width width of the input grayscale image 
  6. * @param height height of the input grayscale image 
  7. */  
  8. void gaussianFilter2 (unsigned char* corrupted, unsigned char* smooth, int width, int height)  
  9. {  
  10.     int templates[25] = { 1, 4, 7, 4, 1,   
  11.                           4, 16, 26, 16, 4,   
  12.                           7, 26, 41, 26, 7,  
  13.                           4, 16, 26, 16, 4,   
  14.                           1, 4, 7, 4, 1 };        
  15.       
  16.     memcpy ( smooth, corrupted, width*height*sizeof(unsigned char) );  
  17.     for (int j=2;j<height-2;j )  
  18.     {  
  19.         for (int i=2;i<width-2;i )  
  20.         {  
  21.             int sum = 0;  
  22.             int index = 0;  
  23.             for ( int m=j-2; m<j 3; m )  
  24.             {  
  25.                 for (int n=i-2; n<i 3; n )  
  26.                 {  
  27.                     sum  = corrupted [ m*width   n] * templates[index ] ;  
  28.                 }  
  29.             }  
  30.             sum /= 273;  
  31.             if (sum > 255)  
  32.                 sum = 255;  
  33.             smooth [ j*width i ] = sum;  
  34.         }  
  35.     }  
  36. }  

 

相关新闻

Direct3D 实现鼠标拾取
理解OpenGL拾取模式(OpenGL Picking)
Picking Tutorial
3D数学:求点到直线的投影
全屏反锯齿 - 多重采样Ⅱ
全屏反锯齿 - 多重采样Ⅰ
乱弹OpenGL选择-拾取机制(下)
乱弹OpenGL选择-拾取机制(上)
对Photoshop高斯模糊滤镜的算法总结

您可能对这些感兴趣  

《VB程序设计基础》选择题
设计模式之Iterator
设计模式之Visitor
设计模式之Interpreter(解释器)
设计模式之Mediator(中介者)
设计模式之Strategy(策略)
设计模式之State
设计模式之Command
设计模式之Chain of Responsibility(职责链)
设计模式之Observer

题目筛选器
日期:
类型:
状态:
得分: <=
分类:
作者:
职业:
关键字:
搜索

 
 
 
  焦点事件
 
  知识体系
 
  职业列表
 
 
  最热文章
 
 
  最多引用文章
 
 
  最新文章
 
 
 
 
网站介绍 | 广告服务 | 招聘信息 | 保护隐私权 | 免责条款 | 法律顾问 | 意见反馈
版权所有 不得转载
沪ICP备 10203777 号 联系电话:021-54428255
  帮助提示    
《我的太学》是一种全新的应用,您在操作中遇到疑问或者问题,请拨打电话13564659895,15921448526。
《我的太学》