[Image] OpenCV 4 median filter

First, the programming environment:

OpenCV  4.1.0
HERE Visual Studio 2017 Enterprise (15.9.13)
operating system Windows 10 x64 Chinese Professional Edition (1903)

Second, the median filtering the image:

It is the statistical median filter is essentially a sort of filter, median filter for a particular type of noise (impulse noise) will achieve a better image denoising, an image is one of the common methods to noise enhancement.

Median filtering window is also moved in the image, the ROI corresponding to its coverage area, sorting all the pixel values, taking the median value of the center pixel as the output point.

Third, the program description:

  • OpenCV median filtering function: medianBlur ()
void medianBlur( InputArray    src, 
                 OutputArray   dst, 
                 int           ksize   //必是大于1的奇数值
               );

Fourth, the program code:

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

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
	Mat src = imread("../images/test.jpg");
	if (src.empty()) {
		printf("不能加载图像!\n");
		return -1;
	}
	namedWindow("1--原图", WINDOW_AUTOSIZE);
	imshow("1--原图", src);

	Mat dst;
	//图像中值滤波
	medianBlur(src, dst, 5);
	imshow("2--medianblur(ksize=5)", dst);

	waitKey(0);
	return 0;
}

Fifth, the operating results:

Text the top right corner of the filtered image is ablated attention of many.

 

Guess you like

Origin blog.csdn.net/kingkee/article/details/93614399