0027-用OpenCV的GaussianBlur函数做高斯滤波

高斯滤波器是一类根据高斯函数的形状来选择权值的线性平滑滤波器,听说高斯滤波器对于服从正太分布(高斯分布)的噪声非常有效,然而实际来看,貌似效果也不怎么样啊,具体的大家可以看本篇帖子代码的运行结果,是笔者哪里没操作对么?
GaussianBlur函数原型如下
C++: void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT )
参数意义如下:
src:输入图像。
dst:输出图像。
ksize:核算子大小(核算子的概念见博文 https://blog.csdn.net/lehuoziyuan/article/details/84101788)。
sigmaX:高斯核在X方向上的标准差,如果写为0,则由ksize.width计算出一个sigmaX。
sigmaY:高斯核在X方向上的标准差,如果写为0,则和sigmaX一样;如果sigmaX也为0,则由ksize.height计算出一个sigmaY。
borderType:这个参数的意义详见博文https://blog.csdn.net/lehuoziyuan/article/details/84101788
示例代码如下

图像处理开发资料、图像处理开发需求、图像处理接私活挣零花钱,可以搜索公众号"qxsf321",并关注!
代码中用到的图像的下载链接为:http://pan.baidu.com/s/1c2ETzwc 密码:pvnz

//opencv版本:OpenCV3.0
//VS版本:VS2013
//Author:qxsf321.net

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>    
#include <opencv2/imgproc/types_c.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <time.h>  
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
        //源图像  
        Mat img_input = imread("zhi_zhi_hua.jpg");


        Mat img_output(img_input.size(), img_input.type());
        Mat noise(img_input.size(), img_input.type());  /**创建一个噪声矩阵*/
        RNG rng(time(NULL));
        rng.fill(noise, RNG::NORMAL, 10, 36);  /**高斯分布*/
        cv::add(img_input, noise, img_output);//为原图像添加高斯噪声

        imshow("原图像", img_input);
        //imshow("噪声图像", noise);
        imshow("加上高斯噪声后的图像", img_output);

        Mat dst;
        GaussianBlur(img_output, dst, Size(5, 5),0, 0);

        imshow("高斯滤波后的图像", dst);

        waitKey(0);
        return EXIT_SUCCESS;
}

运行结果截图如下

从截图中可以看出高斯滤波对高斯噪声的效果好么?我是没看出来....

猜你喜欢

转载自blog.csdn.net/lehuoziyuan/article/details/84102935
今日推荐