admin 管理员组文章数量: 887021
【c++
every blog every motto: You can do more than you think.
=blog
0. 前言
1. 高斯滤波
#include <iostream>
#include <opencv2/opencv.hpp>
#include"Salt.h"using namespace std;
using namespace cv;// 定义高斯滤波函数
void myfilter(int filter_size,Mat& img_input,Mat& img_output);int main(){Mat img,img_gray,img_out,img_out2;img = imread("/home/v/home.png");if (img.empty()){cout<<"can't open the image"<<endl;return -1;}imshow("img",img);cvtColor(img,img_gray,COLOR_BGR2GRAY);Salt(img_gray,1000);imshow("img_gray",img_gray);// Opencv 自带的滤波int a= 7;GaussianBlur(img_gray,img_out,Size(a,a),2,2);imshow("GaussianBlur",img_out);// 自定义高斯滤波myfilter(a,img_gray,img_out2);imshow("myfilter",img_out2);waitKey(0);return 0;
}void myfilter(int filter_size,Mat& img_input,Mat& img_output){img_output = img_input.clone();int k = (filter_size-1)/2;for (int i = k; i < img_input.rows-k; i++){for (int j = k; j < img_input.cols-k; j++){double sum = 0.0;double sum1 = 0.0;double sigma = 7;double g;for (int m = -k; m <= k; m++){for (int n = -k; n <= k; n++){g = exp(-(m*m+n*n)/(2*sigma*sigma));sum += g*img_input.at<uchar>(i+m,j+n);sum1 += g;}}img_output.at<uchar>(i,j) = (int)(sum/sum1);}}}
本文标签: c
版权声明:本文标题:【c++ 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1716923909h690166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论