双边滤波算法的简易实现bilateralFilter
2015-12-16 23:13
218 查看
没怎么看过双边滤波的具体思路,动手写一写,看看能不能突破一下。
最后,感觉算法还是要分开 水平 与 垂直 方向进行分别处理,才能把速度提上去。
没耐性写下去了,发上来,给大伙做个参考好了。
先上几张效果图。
半径参数为10.
见图,磨皮降噪效果还不错。
具体代码如下:
抛砖引玉一下,算法思路比较清晰。
懒得描述细节,代码很短,看代码吧。
最后,感觉算法还是要分开 水平 与 垂直 方向进行分别处理,才能把速度提上去。
没耐性写下去了,发上来,给大伙做个参考好了。
先上几张效果图。
半径参数为10.
见图,磨皮降噪效果还不错。
具体代码如下:
void bilateralFilter(unsigned char* pSrc, unsigned char* pDest, int width, int height, int radius) { float delta = 0.1f; float eDelta = 1.0f / (2 * delta * delta); int colorDistTable[256 * 256] = { 0 }; for (int x = 0; x < 256; x++) { int * colorDistTablePtr = colorDistTable + (x * 256); for (int y = 0; y < 256; y++) { int mod = ((x - y) * (x - y))*(1.0f / 256.0f); colorDistTablePtr[y] = 256 * exp(-mod * eDelta); } } for (int Y = 0; Y < height; Y++) { int Py = Y * width; unsigned char* LinePD = pDest + Py; unsigned char* LinePS = pSrc + Py; for (int X = 0; X < width; X++) { int sumPix = 0; int sum = 0; int factor = 0; for (int i = -radius; i <= radius; i++) { unsigned char* pLine = pSrc + ((Y + i + height) % height)* width; int cPix = 0; int * colorDistPtr = colorDistTable + LinePS[X] * 256; for (int j = -radius; j <= radius; j++) { cPix = pLine[ (X + j+width)%width]; factor = colorDistPtr[cPix]; sum += factor; sumPix += (factor *cPix); } } LinePD[X] = (sumPix / sum); } } }
抛砖引玉一下,算法思路比较清晰。
懒得描述细节,代码很短,看代码吧。
相关文章推荐
- Linux下Shell乘除加减运算
- Linux虚拟主机服务器一个空间多个网站以及其中.htaccess的重写
- POJ 1328:Radar Installation 经典贪心
- sql server 2008服务器连接报错
- 双边滤波算法的简易实现bilateralFilter
- Halo
- Java学习笔记(5):2.面向对象之对象的this引用
- 【数据结构实验】图的深度优先/广度优先遍历
- 【jQuery】:has(selector)过滤选择器
- 1060. Are They Equal (25)【字符串处理】——PAT (Advanced Level) Practise
- Daily Scrum NO.6
- 【iCore3 双核心板】例程十五:USB_CDC实验——高速数据传输
- Android 性能优化之(1)-MAT使用教程
- Linux段页式管理思想--写操作系统内存管理必备知识,简单易懂
- 【12.16】VC++调用Word OLE进行自动化生成报表
- 关于validate.js中remote的使用
- 虚表
- 1020
- ios开发 之 设置多种文字颜色/背景色/文字下划线/行间距
- QT常用的方法