vs2015+opencv3.3.1 实现 c++ 彩色高斯滤波器(Gaussian Smoothing, Gaussian Blur, Gaussian Filter)
//高斯滤波器 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)的更多相关文章
- vs2015+opencv3.3.1 实现 c++ 灰度高斯滤波器
#include <opencv2\highgui\highgui.hpp> #include <iostream> #include<vector> using ...
- win7下VS2015+opencv3.1.0配置
由于opencv与vs的适配版本不同,本人在官网下载opencv3.1.0,其可以和VS2013.VS2015适配,文中以VS2015为例 opencv2.4.13-----vc11;vc12 ope ...
- [转]VS2015+OpenCV3.3 GPU模块和opencv_contrib模块的编译以及采用CMake编译opencv_contrib时提示“No extra modules found in folder”问题的解决方案
据官方说法,目前还不是太稳定的算法模块都在opencv_contrib里边,由于不稳定,所以不能在release版本里发行,只有在稳定以后才会放进release里边.但是这里边有很多我们经常要用的算法 ...
- Win10 64位+VS2015+Opencv3.3.0安装配置
Win10 64位+VS2015+Opencv3.3.0安装配置 1.我们首先下载VS2015.OpenCV3.3.0. 1.1 VS2015下载 在官网https://visualstudio.mi ...
- win10+VS2015+opencv3.4.0配置方法
win10+VS2015+opencv3.4.0配置方法 操作环境: windows10 64位opencv 3.4.0:https://opencv.org/releases.html(选择open ...
- 高斯拉普拉斯算子(Laplace of Gaussian)
高斯拉普拉斯(Laplace of Gaussian) kezunhai@gmail.com http://blog.csdn.net/kezunhai Laplace算子作为一种优秀的边缘检测算子, ...
- C++实现高斯滤波器
在matlab中,我们经常用到高斯滤波器,生成滤波器一般都是这样的函数psf = fspecial('gauss', GaussSize, sigma),但是在vs2010中用到的高斯滤波器不能自 ...
- 二维高斯滤波器(gauss filter)的实现
我们以一个二维矩阵表示二元高斯滤波器,显然此二维矩阵的具体形式仅于其形状(shape)有关: def gauss_filter(kernel_shape): 为实现二维高斯滤波器,需要首先定义二元高斯 ...
- win10+vs2015+opencv3.0 x86/x64配置(debug+release)
最近做一些图像识别的项目,用到了opencv,opencv3.1没有x86版本,所以只能用opencv3.0来完成,下面介绍一下在window10下vs2015 配置opencv3.0的过程(x86和 ...
随机推荐
- sublime text3 自动编译php 适合用于简单的php文件执行
1.将php路径放入环境变量中 2. 点击 sublime_text的“工具”->"编译系统"->"编译新系统" { "cmd" ...
- 如果axios请求失败,如何获取后端接口返回的状态码及错误信息
这两天在工作中遇到一个问题,一个请求返回400错误,我需要向用户展示后端返回的错误信息,但是用普通的catch方法只能获取到浏览器返回的400错误提示,不能获取到后端返回的,后经查阅得出下面方法: a ...
- Cassandra学习五 使用Key的正确姿势
NoSQL一般是反范式的,比如提倡数据冗余,使得不至于写出非常复杂的SQL语句. Cassandra之中一共包含下面5中Key: Primary Key: 用来获取某一行的数据,可以是一列或多列 ...
- ubuntu 14.04使用root登陆出现错误“Error found when loading /root/.profile”解决
在刚修改完root权限自动登录后,发现开机出现以下提示: Error found when loading /root/.profile stdin:is not a tty ----........ ...
- 密码生成工具Cupp
Cupp可根据已知信息生成相应的字典,用来爆破很有帮助 首先先安装一下cupp 命令:apt-get install cupp 参数说明: -v查看cupp版本号 -h 查看参数列表 -l 从gith ...
- Cygwin windows10上安装出现系列问题及解决方法
问题1描述: 发现vim不好使,Backspace键只是前移,不能删除,按方向键更是按出ABCD来. 解决方法: $ cp /usr/share/vim/vim73/vimrc_example.v ...
- python----python使用mysql
Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymql pymsql是Python中操作MySQL的模块,在windows中的安装: pip ...
- VB.NET使用TagLib#读取MP3中的ID3v2标签
Taglib#是一个为.NET开发的元数据读取类库,为一个开源项目,可以在他们的官网上获取windows版本的源码包或者编译好的类库:http://download.banshee.fm/taglib ...
- 【知识碎片】python 篇
领域:运维 网站 游戏 搜索 嵌入式 C/S软件 Openstack二次开发 绿色版:Portable Python 面向对象.解释型动态语言 env python 切换版也好使,自己寻找系统中pyt ...
- 【知识碎片】 Linuxb 篇
3.登录mysql 开启MySQL服务后,使用MySQL命令可以登录.一般使用mysql -uroot -p即可.如果数据库不是本机,则需要加参数,常用参数如下:1,-h,指定ip地址,默认为loca ...