中值滤波
中值滤波对椒盐噪声有很好的抑制作用
均值模糊无法克服边缘像素信息丢失缺陷。原因是均值滤波是基于平均权重
高斯模糊部分克服了该缺陷,但是无法完全避免,因为没有考虑像素值的不同
高斯双边模糊 – 是边缘保留的滤波方法,避免了边缘信息丢失,保留了图像轮廓不变
中值模糊medianBlur(Mat src, Mat dest, ksize)
双边模糊bilateralFilter(src, dest, d=15, 150, 3);
- 15 –计算的半径,半径之内的像数都会被纳入计算,如果提供-1 则根据sigma space参数取值
- 150 – sigma color 决定多少差值之内的像素会被计算
- 3 – sigma space 如果d的值大于0则声明无效,否则根据它来计算d值
中值模糊的ksize大小必须是大于1而且必须是奇数。
#include "pch.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char** argv) {
Mat src, dst;
src = imread("D:/lena.jpg");
if (!src.data) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src);
//medianBlur(src, dst, 3);
//高斯双边模糊
bilateralFilter(src, dst, 15, 100, 5);
namedWindow("BiBlur Filter Result", CV_WINDOW_AUTOSIZE);
imshow("BiBlur Filter Result", dst);
Mat resultImg;
Mat kernel = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
filter2D(dst, resultImg, -1, kernel, Point(-1, -1), 0);
imshow("Final Result", resultImg);
waitKey(0);
return 0;
}

网友评论