#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include<vector> using namespace cv;
using namespace std;
void gaussianFilter2(vector<uchar> corrupted, vector<uchar> &smooth, int width, int height)
{
int templates[25] = { 1, 4, 7, 4, 1,
4, 16, 26, 16, 4,
7, 26, 41, 26, 7,
4, 16, 26, 16, 4,
1, 4, 7, 4, 1 }; //滤波器模板 smooth=corrupted; //复制像素
for (int j = 0; j<height ; j++)
{
for (int i =0; i<width ; i++)
{
int sum = 0;
int index = 0;
for (int m = j - 2; m<j + 3; m++)
{
for (int n = i - 2; n<i + 3; n++)
{if (m<0 || n<0 || m>height - 1 || n>width - 1)continue;  //边缘处理
sum += corrupted[m*width + n] * templates[index++];
}
}
sum /= 273;
if (sum > 255)
sum = 255;
smooth[j*width + i] = sum;
}
}
} int main() { Mat img = imread("123.jpg", 0);
cout << img.rows*img.cols;
// namedWindow("MyWindow");
// imshow("MyWindow", img); vector<uchar> array(img.rows*img.cols);
if (img.isContinuous()) { array.assign(img.datastart, img.dataend); } cout << array.size(); vector<uchar> no(img.rows*img.cols); gaussianFilter2(array, no,img.cols ,img.rows ); Mat now((int)img.rows, (int)img.cols, 0);
for (int i = 0; i < img.rows; i++)
for (int j = 0; j < img.cols; j++)
now.at<uchar>(i, j) = no[i*img.cols + j]; // namedWindow("MyWindow1");
// imshow("MyWindow1", now);
// waitKey(0);
imwrite("1123.jpg", now);
system("pause"); return
0; }

  

vs2015+opencv3.3.1 实现 c++ 灰度高斯滤波器的更多相关文章

  1. vs2015+opencv3.3.1 实现 c++ 彩色高斯滤波器(Gaussian Smoothing, Gaussian Blur, Gaussian Filter)

    //高斯滤波器 https://github.com/scutlzk#include <opencv2\highgui\highgui.hpp> #include <iostream ...

  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. C++实现高斯滤波器

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

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

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

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

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

  9. opencv配置(win10+VS2015+opencv3.1)

    Step 1:准备工作 a.win10 b.vs2015 c.opencv3.1[从http://opencv.org/downloads.html下载] Step 2.开始安装 a. 双击openc ...

随机推荐

  1. PHP下的命令行执行 php -S localhost -t public(public是根目录,也是入口文件所在目录,是LARAVEL的)

    PHP 的命令行模式     以下是 PHP 二进制文件(即 php.exe 程序)提供的命令行模式的选项参数,您随时可以通过 PHP -h 命令来查询这些参数. Usage: php [option ...

  2. fullCalendar动态获取数据

    fullCalendar http://fullcalendar.io/docs/event_data/events_function $('#calendar').fullCalendar({ he ...

  3. MFC学习(六)计算器

    1 stdafx.h  所谓头文件预编译,就是把一个工程(Project)中使用的一些MFC标准头文件(如Windows.H.Afxwin.H)预先编译,以后该工程编译时,不再编译这部分头文件,仅仅使 ...

  4. oracle下载地址

    12c 下载地址 http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html

  5. 3.solr学习速成之索引添加 查询 删除

    solrserver.java public class solrServer { private solrServer(){}; final static String SOLR_URL = &qu ...

  6. Mybites和hibernate的优缺点和区别2

    Hibernate与MyBatis都可以是通过SessionFactoryBuider由XML配置文件生成SessionFactory,然后由SessionFactory 生成Session,最后由S ...

  7. 自定义ListView里面的Item的内容

    我们不可能满足只是往每个item里面填字就足够,像QQ的好友列表就是一个ListView,每个Item里面有头像.名字啊.签名什么的,内容丰富.那我们要怎么定义一个内容丰富的item呢? 要用到Ada ...

  8. Spring配置文件中<bean>标签的scope属性

    转自:https://fj-sh-chz.iteye.com/blog/1775149 singleton  (默认属性) Spring将Bean放入Spring IOC容器的缓存池中,并将Bean引 ...

  9. ClientDataSet1.LoadFromStream

    lStream3.Position := 0;        lDataSet.LoadFromStream(lStream3);

  10. asp.net js 存取cookie

    asp.net //传进来的 public BaseController(BaseHttpHandler handler, HttpContext context) // { //根据地址设置cook ...