OpenCV-Learning Course 8- Image Blur 1 (Basic Knowledge, Median Blur, Gaussian Blur)

The OPENCV series of blogs mainly record the process of learning OPENCV and store the implemented code for subsequent review. The code contains the main remarks.

 1. The principle of image blur

        1. Blur function: eliminate noise, use before taking edge.

       2. In the formula : f(i,j) original image, h(k,l) convolution kernel/mask

        3. Convolution principle: the mask is multiplied by the corresponding pixels of the image, a total of 9 numbers (3x3 mask), these 9 numbers are added and averaged and stored in the center. From left to right, from top to bottom, until the picture is traversed.

              3.1 Mean filtering: all pixels have the same weight, and all pixels are added together to get the average

              3.2 Gaussian filtering: all pixels have different weights (inverted pendulum shape)

        

         

          

           

 

2. Obscure related API

3. Code implementation


#include <opencv2/opencv.hpp>
#include <iostream>


using namespace std;
using namespace cv;


int main(int argc, char** argv) {
	
	//Step1 读取图片
	Mat src, dst;
	src = imread("E:/OpenCVLearning/Project/source_image/sample.jpg"); //注意斜线方向
	if (!src.data) {
		cout << "Could not load the image ...." << endl;
		return -1;
	}

	//Step2 自定义输入输出窗口
	char input_title[] = "input image";
	char output_title1[] = "output middle image";
	char output_title2[] = "output Gauss image";
	namedWindow(input_title,CV_WINDOW_AUTOSIZE);
	namedWindow(output_title1, CV_WINDOW_AUTOSIZE);
	namedWindow(output_title2, CV_WINDOW_AUTOSIZE);
	imshow(input_title,src);

	//Step3 测试均值模糊!!!

	blur(src,dst,Size(5,5),Point(-1,-1)); //(输入图,输出图,掩膜大小,掩膜中心在掩膜的位置:就是中值求和后存在哪里)
										  //也可以只设置Size的x或者y,这样就只滤波同一行或同一列
	imshow(output_title1,dst);


	//Step3 测试高斯模糊!!!

	Mat gauss_image;
	GaussianBlur(src, gauss_image,Size(5, 5),11,11); //(输入图,输出图,高斯卷积核大小,α1/2

	imshow(output_title2, gauss_image);


	waitKey(0);
	return 0;
}

4. Operation effect

Guess you like

Origin blog.csdn.net/weixin_42503785/article/details/113914868