//高斯滤波器 https://github.com/scutlzk
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <vector> using namespace cv;
using namespace std; void Get_Gaussian_Kernel(double*& gaus_1, const int size, const double sigma_s)
{
gaus_1 = new double[size*size];
double **gaus = new double*[size];
for (int i = 0; i<size; i++)gaus[i] = new double[size]; double sum = 0;
for (int i = -size / 2; i<size / 2 + 1; i++) {
for (int j = -size / 2; j<size / 2 + 1; j++) {
gaus[i + size / 2][j + size / 2] = exp(-((i*i) + (j*j)) / (2 * sigma_s*sigma_s));
sum += gaus[i + size / 2][j + size / 2];
}
} for (int i = 0; i<size; i++) {
for (int j = 0; j<size; j++) {
gaus[i][j] /= sum;
gaus_1[i*size + j] = gaus[i][j]; //使用一维更简单
}
} return;
} void Gaussian_Filter(const char *filename, Mat *&dst,const int size,const double sigma_s)
{
double* templates;
Get_Gaussian_Kernel(templates, size, sigma_s);
Mat src = imread(filename, 3);
dst = new Mat(src.rows, src.cols, CV_8UC3);
namedWindow("src");
imshow("src", src);
for (int j = 0; j<src.rows; j++)
{
for (int i = 0; i<src.cols; i++)
{
double sum0 = 0;
double sum1 = 0;
double sum2 = 0;
int index = 0;
for (int m = j - size/2; m<j + size/2+1; m++)
{
for (int n = i - size / 2; n<i + size / 2 + 1; n++)
{ if (m<0 || n<0 || m>src.rows - 1 || n>src.cols - 1) { index++; continue; }//边缘不处理
sum0 += src.at<Vec3b>(m, n)[0] * templates[index++];
sum1 += src.at<Vec3b>(m, n)[1] * templates[index-1];
sum2 += src.at<Vec3b>(m, n)[2] * templates[index-1]; }
}
sum0 > 255 ? 255 : sum0;
sum1 > 255 ? 255 : sum1;
sum2 > 255 ? 255 : sum2; (*dst).at<Vec3b>(j, i)[0] = sum0;
(*dst).at<Vec3b>(j, i)[1] = sum1;
(*dst).at<Vec3b>(j, i)[2] = sum2;
}
} namedWindow("dst");
imshow("dst", *dst);
waitKey(0);
return;
} int main() {
const char *filename = "123.jpg";
const int Gaussian_Kernel_Size = 9;
const double sigma_s = 3; Mat *dst;
Gaussian_Filter(filename, dst, Gaussian_Kernel_Size, sigma_s);
imwrite("1234.jpg", *dst);
return 0; }

  

vs2015+opencv3.3.1 实现 c++ 彩色高斯滤波器(Gaussian Smoothing, Gaussian Blur, Gaussian Filter)的更多相关文章

  1. vs2015+opencv3.3.1 实现 c++ 灰度高斯滤波器

    #include <opencv2\highgui\highgui.hpp> #include <iostream> #include<vector> using ...

  2. win7下VS2015+opencv3.1.0配置

    由于opencv与vs的适配版本不同,本人在官网下载opencv3.1.0,其可以和VS2013.VS2015适配,文中以VS2015为例 opencv2.4.13-----vc11;vc12 ope ...

  3. [转]VS2015+OpenCV3.3 GPU模块和opencv_contrib模块的编译以及采用CMake编译opencv_contrib时提示“No extra modules found in folder”问题的解决方案

    据官方说法,目前还不是太稳定的算法模块都在opencv_contrib里边,由于不稳定,所以不能在release版本里发行,只有在稳定以后才会放进release里边.但是这里边有很多我们经常要用的算法 ...

  4. Win10 64位+VS2015+Opencv3.3.0安装配置

    Win10 64位+VS2015+Opencv3.3.0安装配置 1.我们首先下载VS2015.OpenCV3.3.0. 1.1 VS2015下载 在官网https://visualstudio.mi ...

  5. win10+VS2015+opencv3.4.0配置方法

    win10+VS2015+opencv3.4.0配置方法 操作环境: windows10 64位opencv 3.4.0:https://opencv.org/releases.html(选择open ...

  6. 高斯拉普拉斯算子(Laplace of Gaussian)

    高斯拉普拉斯(Laplace of Gaussian) kezunhai@gmail.com http://blog.csdn.net/kezunhai Laplace算子作为一种优秀的边缘检测算子, ...

  7. C++实现高斯滤波器

    在matlab中,我们经常用到高斯滤波器,生成滤波器一般都是这样的函数psf =   fspecial('gauss', GaussSize, sigma),但是在vs2010中用到的高斯滤波器不能自 ...

  8. 二维高斯滤波器(gauss filter)的实现

    我们以一个二维矩阵表示二元高斯滤波器,显然此二维矩阵的具体形式仅于其形状(shape)有关: def gauss_filter(kernel_shape): 为实现二维高斯滤波器,需要首先定义二元高斯 ...

  9. win10+vs2015+opencv3.0 x86/x64配置(debug+release)

    最近做一些图像识别的项目,用到了opencv,opencv3.1没有x86版本,所以只能用opencv3.0来完成,下面介绍一下在window10下vs2015 配置opencv3.0的过程(x86和 ...

随机推荐

  1. monolog 应该是世界上最好的日志插件了

    引入 composer require monolog/monolog 官网 https://github.com/Seldaek/monolog 创建工具类 <?php /** * Creat ...

  2. windows环境下,安装zookeeper~

    1.   概述 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂 ...

  3. [Kingdom Rush]团队分享:如何做塔防手游

    转自:http://www.gamelook.com.cn/2015/03/207324 GameLook报道/2014年11月,乌拉圭开发商Ironhide Studios发布的<Kingdo ...

  4. MyBatis 工具 pndao - 自动写 SQL

    pndao的原理并不复杂,是基于MyBatis的方法命名约定来生成SQL,并且写入MyBatis需要的XML. 写之前会判断是否已经存在XML或者注解,如果已经存在则略过此方法,所以无论是注解还是XM ...

  5. Cocos暂停和重新开始游戏

    创建按钮 cc.MenuItemFont.setFontSize(18); cc.MenuItemFont.setFontName("Arial"); var systemMenu ...

  6. 固定容器内任意个div填充算法

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. Python多线程-生产者消费者模型

    用多线程和队列来实现生产者消费者模型 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import threading imp ...

  8. leetcode452

    public class Solution { public int FindMinArrowShots(int[,] points) { // multidimensional array cann ...

  9. Win7 IE11 F2无法切换版本

    Win7 IE11 F2无法切换版本 http://www.microsoft.com/zh-cn/download/confirmation.aspx?id=45154 选择操作系统对应的版本 ht ...

  10. delphi c++builder 判断工程类型 超级系统变量

    d:\program files (x86)\embarcadero\studio\16.0\SOURCE\RTL\SYS\SysInit.pas ModuleIsLib: Boolean;      ...