高斯模糊
高斯核从最中心到边缘的权值逐渐变小,服从如下正态分布,从而使得中心像素占的比例最大。
API:
sigmaX Gaussian kernel standard deviation in X direction. 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 semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY. borderType pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported. 窗口尺寸设置要求为正数且为奇数,因为偶数无法中心化。
当设置了Size的时候,sigma的设置将无效果。
当窗口尺寸设置为(0,0)时, 模糊效果会达到最佳。
高斯双边模糊
对于空间(x、y)和色彩域内做卷积操作,会考虑色彩空间像素值的差异,只对同一通道内差异大的像素值进行处理。
API:
int d 设置为0;
sigmaColor应设置一个较大的值,sigmaSpace为sigmaColor的1/10左右。
代码:
void QuickDemo::gaussian_blur_demo(Mat& image)
{
Mat dst;
GaussianBlur(image, dst, Size(0, 0), 15);
imshow("高斯模糊", dst);
Mat dst2;
bilateralFilter(image, dst2, 0, 100, 10);
imshow("高斯双边模糊", dst2);
}
高斯双边模糊结果: