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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:vs2015+opencv3.3.1 实现 c++ 彩色高斯滤波器(Gaussian Smoothing, Gaussian Blur, Gaussian Filter)
下一篇:实现求解线性方程(矩阵、高斯消去法)------c++程序设计原理与实践(进阶篇)

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月04日 02时01分36秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章