vs2015+opencv3.3.1 实现 c++ 灰度高斯滤波器
2024-08-29 21:05:27
#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; }
最新文章
- [转]Android开源项目第二篇——工具库篇
- 关于Response.Redirect和Server.Execute的区别
- Android中将xml布局文件转化为View树的过程分析(上)
- 《head first java 》读书笔记(五)
- 自定义View 实现软键盘实现搜索
- vbs脚本发送邮件
- iOS远程消息推送自我整理版
- Entity Framework 4.1 绕过 EF 查询映射
- Python定时任务
- Arduino语言简介
- Java笔试面试题整理第八波
- 解决linux下“XX不在 sudoers 文件中。此事将被报告";的问题
- Centos 7 安装 Supervisor 及使用
- py-faster-rcnn代码阅读3-roidb.py
- Creating Reusable XAML User Controls with Xamarin Forms
- unity 打包资源及网络请求资源包
- vscode 自定义快捷键
- c++学习之map基本操作
- A Node Influence Based Label Propagation Algorithm for Community detection in networks 文章算法实现的疑问
- 配置Ubuntu16.04虚拟机 (用途:CTF_pwn)