一.实验目的:
- 掌握opencv开发环境中对灰度图像及彩色图像中的像素的访问方法
- 掌握opencv中对图像进行处理的基本过程。
- 掌握均值平滑和中值滤波的基本原理。
二.实验内容:
- 打开一幅灰度图像,对图像进行3*3(包括中心点)的邻域平均处理。
- 对原图进行3*3(包括中心点)的中值滤波处理。
- 比较原图像与邻域平均的图像、中值滤波后的图像的差异。
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
using namespace std;
using namespace cv;
int k[9];
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);
void Convlution1(Mat InputImage, Mat OutputImage, Mat kernel)
{
//卷积核半径
int sub_x = kernel.cols / 2;
int sub_y = kernel.rows / 2;
//遍历图片
for (int image_y = 0; image_y < InputImage.rows - 2 * sub_y; image_y++)
{
for