OpenCv图像处理之高斯滤波-线性滤波(三)

OpenCv图像处理之高斯滤波-线性滤波

高斯滤波是一种线性平滑滤波,适用于消除高斯噪声,广泛应用于图像处理的减噪过程。通俗的讲,高斯滤波就是对整幅图像进行加权平均的过程,每一个像素点的值,都由其本身和邻域内的其他像素值经过加权平均后得到。
高斯滤波后图像被平滑的程度取决于标准差。它的输出是领域像素的加权平均,同时离中心越近的像素权重越高。因此,相对于均值滤波(mean filter)它的平滑效果更柔和,而且边缘保留的也更好。
高斯滤波被用作为平滑滤波器的本质原因是因为它是一个低通滤波器(让某一频率以下的信号分量通过,而对该频率以上的信号分量大大抑制)

先来看一下源码中对cv::GaussianBlur()函数声明和参数介绍

CV_EXPORTS_W void medianBlur(InputArray src, OutputArray dst, int ksize);

//输入图片可以有任意的通道数,各个通道分别进行处理,但是深度要是
//CV_8U, CV_16U, CV_16S, CV_32F or CV_64F中的一种
@param src input image; the image can have any number of channels, which are processed
independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
//输出图像要拥有和src相同的尺寸和类型
@param dst output image of the same size and type as src.
//高斯核大小可以不同但是必须是大于0的奇数,若他们都为0时,则它们的大小取决于sigma的计算
@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be
positive and odd. Or, they can be zero's and then they are computed from sigma.
//sigmaX为高斯核在X轴方向的标准差
@param sigmaX Gaussian kernel standard deviation in X direction.
//sigmaY为高斯核在Y轴方向的标准差,如果sigmaY为0,那么它的值将设置为sigmaX的值,若sigmaX和sigmaY值都为0,则它们分别由kesize的width和kesize.height进行计算
@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be
equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,
respectively (see #getGaussianKernel for details); to fully control the result regardless of
possible future modifications of all this sematicns, it is recommended to specify all of ksize,
sigmaX, and sigmaY.
@param borderType pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
#include <opencv2/opencv.hpp>
#include <string>
#include <iostream>

using namespace std;
using namespace cv;


int main() {
    
    
    Mat image, clone_img;
    image = imread("D:/cat.jpg", IMREAD_COLOR);
    clone_img = image.clone();
    resize(clone_img, clone_img, Size(int(clone_img.cols * 0.5),
                                      int(clone_img.rows * 0.5)), 0, 0, INTER_AREA);
    Mat dst = Mat::zeros(Size(clone_img.cols, clone_img.rows), clone_img.type());
    cv::GaussianBlur(clone_img, dst, Size(9, 9), 1.1);
    imshow("small_scale", dst);
    cv::GaussianBlur(clone_img, dst, Size(101, 101), 1.1);
    imshow("img", dst);
    cv::GaussianBlur(clone_img, dst, Size(5, 5), 1000.1);
    imshow("dst", dst);
    waitKey(0);
    return 0;
}

效果显示
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_35140742/article/details/120086687