中值滤波——medianBlur()
原理
中值滤波程序
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define FILTER_ORIGINAL_WINDOW_NAME "中值滤波【原图】"
#define FILTER_RESULT_WINDOW_NAME "中值滤波【效果图】"
int main()
{
//载入原图
Mat image = imread("test.jpg");
//创建窗口
namedWindow(FILTER_ORIGINAL_WINDOW_NAME);
namedWindow(FILTER_RESULT_WINDOW_NAME);
//显示原图
imshow(FILTER_ORIGINAL_WINDOW_NAME, image);
//进行中值滤波操作
Mat out;
medianBlur(image, out, 7);
//显示效果图
imshow(FILTER_RESULT_WINDOW_NAME, out);
waitKey(0);
destroyAllWindows();
return 0;
}
双边滤波——bilateralFilter()
原理
双边滤波程序
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define FILTER_ORIGINAL_WINDOW_NAME "双边滤波【原图】"
#define FILTER_RESULT_WINDOW_NAME "双边滤波【效果图】"
int main()
{
//载入原图
Mat image = imread("test.jpg");
//创建窗口
namedWindow(FILTER_ORIGINAL_WINDOW_NAME);
namedWindow(FILTER_RESULT_WINDOW_NAME);
//显示原图
imshow(FILTER_ORIGINAL_WINDOW_NAME, image);
//进行双边滤波操作
Mat out;
bilateralFilter(image, out, 25, 25 * 2, 25 / 2);
//显示效果图
imshow(FILTER_RESULT_WINDOW_NAME, out);
waitKey(0);
destroyAllWindows();
return 0;
}