概述
这个函数用来对图像进行中值滤波。
这个函数用法比较简单,但在消除噪音方面,效果比 均值滤波 好很多。
函数
void cv::medianBlur
(
InputArray src,
OutputArray dst,
int ksize
)
src | 源图像 |
dst | 输出图像 |
ksize | 卷积核的大小 |
测试代码
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
using namespace cv;
using namespace std;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//载入源图像
Mat src = imread("c:/opencv/jqm.png");
//显示
imshow("src",src);
//中值滤波3
Mat dst3;
medianBlur(src,dst3,3);
imshow("dst3",dst3);
//中值滤波5
Mat dst5;
medianBlur(src,dst5,5);
imshow("dst5",dst5);
//中值滤波7
Mat dst7;
medianBlur(src,dst7,7);
imshow("dst7",dst7);
}
Widget::~Widget()
{
delete ui;
}
测试结果
运行代码,可以看出,中值滤波对 椒盐噪音 有比较好的处理效果 。
卷积核的越大,处理效果越好,但图像越模糊。