一.实验目的:
- 掌握图像与模板卷积的基本过程。
- 通过卷积实现图像平滑,锐化,边缘计算的方法。
- 掌握opencv中对图像进行处理的基本过程。
二.实验内容:
- 编写图像与模板进行卷积操作的函数 Mat myconvolution(Mat inputeImage, Mat template)
- 利用convolution函数,分别采用均值平滑模板,拉普拉斯4领域锐化模板,sobel算子实现图像的平滑,锐化、以及边缘检测。
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <cmath>
using namespace std;
using namespace cv;
void Convlution(Mat InputImage, Mat OutputImage, Mat kernel);
void Convlution(Mat InputImage, Mat OutputImage, Mat Sobel_x, Mat Sobel_y);
Mat myconvolution(Mat InputImage, Mat kernel);
Mat myconvolution(Mat InputImage, Mat Sobel_x, Mat Sobel_y);
string PATH("d:\\mdx.jpg");
Mat MeanSmoothing = (Mat_<double>(3, 3) <<
1.0 / 9, 1.0 / 9, 1.0 / 9,
1.0 / 9, 1.0 / 9, 1.0 / 9,
1.0 / 9, 1.0 / 9, 1.0 / 9);
Mat Laplacian4 = (Mat_<double>(3, 3) <<
0, -1, 0,
-1, 5, -1