在高斯模糊操作中,图像与高斯滤波器而不是盒式滤波器卷积。 高斯过滤器是一个低通过滤器,可以消除高频分量的减少。
可以使用imgproc
类的Gaussianblur()
方法在图像上执行此操作。 以下是这种方法的语法 -
GaussianBlur(src, dst, ksize, sigmaX)
该方法接受以下参数 -
Mat
对象。Mat
对象。Size
对象。double
表示X
方向上的高斯核标准差。以下程序演示如何对图像执行高斯模糊操作。
package com.zyiz.blur; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class GaussianTest { public static void main(String args[]) { // Loading the OpenCV core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Reading the Image from the file and storing it in to a Matrix object String file ="F:/worksp/opencv/images/sample2.jpg"; Mat src = Imgcodecs.imread(file); // Creating an empty matrix to store the result Mat dst = new Mat(); // Applying GaussianBlur on the Image Imgproc.GaussianBlur(src, dst, new Size(45, 45), 0); // Writing the image Imgcodecs.imwrite("F:/worksp/opencv/images/gaussian.jpg", dst); System.out.println("Image Processed"); } }
假定以下是上述程序中指定的输入图像sample2.jpg
。
执行上面示例代码,得到以下结果 -