vs2015+opencv3.3.1 实现 c++ 双边滤波器(Bilateral Filter)
发布日期:2022-04-04 06:36:24
浏览次数:16
分类:博客文章
本文共 2013 字,大约阅读时间需要 6 分钟。
#include#include #include using namespace cv;using namespace std;void GetGaussianKernel(double*& gaus_1, const int size, const double sigma_s);void gaussianFilter2(const vector & corrupted, vector &smooth, double*& templates,const int width,const int height, const double sigma_r, const int size_m);int main() { const double sigma_r = 30; //值域的sigma const double PI = 4.0*atan(1.0); //圆周率π赋值 const int size_m = 5; //模板大小 const double sigma_s = 10; //空间域的sigma double *templates; templates = new double[size_m*size_m]; GetGaussianKernel(templates, size_m, sigma_s); Mat img = imread("123.jpg", 3);// namedWindow("MyWindow");// imshow("MyWindow", img); vector array(img.rows*img.cols*3); if (img.isContinuous()) { array.assign(img.datastart, img.dataend); } vector no(img.rows*img.cols*3); gaussianFilter2(array, no, templates ,int(img.cols)*3, img.rows,sigma_r,size_m); Mat now((int)img.rows, (int)img.cols, CV_8UC3 ); for (int i = 0; i < img.rows; i++) for (int j = 0; j < img.cols; j++) { now.at (i, j)[0] = no[i*img.cols*3 + j*3]; now.at (i, j)[1] = no[i*img.cols*3 + j*3 + 1]; now.at (i, j)[2] =no[i*img.cols*3 + j*3 + 2]; } imwrite("1123.jpg", now); namedWindow("MyWindow1"); imshow("MyWindow1", now); waitKey(0); return 0;}void GetGaussianKernel(double*& gaus_1, const int size, const double sigma_s){ double **gaus = new double*[size]; for (int i = 0; i & corrupted, vector &smooth,double*& templates,const int width,const int height,const double sigma_r, const int size_m) { int len = size_m / 2; smooth = corrupted; //复制像素 for (int j = 0; j height - 1 || n>width - 1)continue; //边缘处理 temp = templates[index++] * exp(-(corrupted[m*width + n] - corrupted[j*width + i])*(corrupted[m*width + n] - corrupted[j*width + i]) / (2.0*sigma_r*sigma_r)); sum += corrupted[m*width + n] * temp; sum_c += temp; } } sum /= sum_c; if (sum > 255) sum = 255; if (sum < 0) sum = 0; smooth[j*width + i] = sum; } }}
转载地址:https://www.cnblogs.com/l2017/p/7944929.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月04日 02时01分36秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
FTP文件管理项目(本地云)项目日报(九)
2019-04-27
以练代学设计模式 -- FTP文件管理项目
2019-04-27
FTP文件管理项目(本地云)项目日报(十)
2019-04-27
学以致用设计模式 之 “组合模式”
2019-04-27
我用过的设计模式(7)--享元模式
2019-04-27
MySQL数据库从入门到实战应用(学习笔记一)
2019-04-27
MySQL数据库从入门到实战应用(学习笔记二)
2019-04-27
种树:二叉树、二叉搜索树、AVL树、红黑树、哈夫曼树、B树、树与森林
2019-04-27
【C++】攻克哈希表(unordered_map)
2019-04-27
转:【答学员问】- 该如何根据岗位学习相关技能
2019-04-27
转:【答学员问】有什么经验教训,是你在面试很多次之后才知道的?
2019-04-27
消息队列:解耦、异步、削峰,现有MQ对比以及新手入门该如何选择MQ?
2019-04-27
【奇技淫巧】-- 三角形最小路径和
2019-04-27
【小技巧】argc和argv的用法
2019-04-27
学不下去了怎么办?
2019-04-27
二叉树的前中后序遍历(迭代法)(带动画)
2019-04-27
【小技巧】【XShell】【Xftp】Windows桌面与Linux虚拟机互传文件
2019-04-27
【redis入门】Centos下安装redis
2019-04-27
【redis入门】redis安装后相关知识串讲
2019-04-27
【redis】来吧,展示一下redis 发布-订阅模式
2019-04-27