码迷,mamicode.com
首页 > 其他好文 > 详细

比较中值模糊和高斯模糊对高斯噪声处理效果

时间:2020-03-15 15:13:11      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:proc   处理   can   cpp   uri   sizeof   out   pac   info   

原图:
技术图片

添加高斯噪声:
技术图片
中值模糊处理:
技术图片
利用高斯模糊处理:
技术图片
代码地址:https://github.com/cyssmile/openCV_learning_notes/blob/master/opencv_test/opencv_020/opencv_020.cpp

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;

void addGaussianNoise(Mat &images, Scalar mean, Scalar meanDev);
void compareMedianBlurAndGaussianDeaGaussianNoise(Mat &images_noise, int SizeOfMedianKenel,
                                        Size GuassianKenel);
int main(int argc, char** argv)
{
    Mat src = imread("D:/images/hl.jpg", -1);
    if (src.empty())
    {
        cout << " can`t open this ph" << endl;
    }
    imshow("src_win", src);
    Mat images_src = src.clone();
    addGaussianNoise(images_src,Scalar(10,10,10),Scalar(30,30,30));
    compareMedianBlurAndGaussianDeaGaussianNoise(images_src, 3, Size(5, 5));
    waitKey(0);
    destroyAllWindows();
    return 0;
}
/*
* add GaussianNoise into source image
* cyssmile
* 2020/3/15
*/
void addGaussianNoise(Mat &images, Scalar mean, Scalar meanDev)
{
    Mat GaussianNoise = Mat::zeros(images.size(), images.type());
    randn(GaussianNoise, mean, meanDev);//randn会产生正态分布的噪声Mat
    Mat GaussianNoiseDst;
    add(images, GaussianNoise, images);
}
/*
* compare medianBlur and GaussianBlur in process a image with Guassian noise
* cyssmile
* 2020/3/15
*/
void compareMedianBlurAndGaussianDeaGaussianNoise(Mat &images_noise, int SizeOfMedianKenel,
                                                Size GuassianKenel)
{
    imshow("Gaussian noise image", images_noise);
    Mat dst;
    medianBlur(images_noise, dst, SizeOfMedianKenel);
    imshow("medianBlur", dst);

    Mat dst1;
    GaussianBlur(images_noise, dst1, GuassianKenel, 0, BORDER_DEFAULT);
    imshow("gaussianBlur", dst1);
}

比较中值模糊和高斯模糊对高斯噪声处理效果

标签:proc   处理   can   cpp   uri   sizeof   out   pac   info   

原文地址:https://www.cnblogs.com/cyssmile/p/12497459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!