📅  最后修改于: 2020-12-14 05:37:25             🧑  作者: Mango
在本章中,我们学习使用高斯滤波器来提高图像的清晰度。
首先,我们使用OpenCV函数GaussianBlur 。可以在Imgproc软件包下找到。其语法如下-
Imgproc.GaussianBlur(source, destination, new Size(0,0), sigmaX);
参数简要描述-
Sr.No. | Parameter & Description |
---|---|
1 |
source It is source image. |
2 |
destination It is destination image. |
3 |
Size It is Gaussian kernel size. |
4 |
sigmaX It is Gaussian kernel standard deviation in X direction. |
此外,我们使用OpenCV函数addWeighted将图像水印应用于图像。可以在Core软件包下找到。其语法如下-
Core.addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst);
该函数的参数如下所述-
Sr.No. | Parameter & Description |
---|---|
1 |
src1 It is first input array. |
2 |
alpha It is weight of the first array elements. |
3 |
src2 It is second input array of the same size and channel number as src1. |
4 |
Beta It is weight of the second array elements. |
5 |
gamma It is scalar added to each sum. |
6 |
dst It is output array that has the same size and number of channels as the input arrays. |
除了GaussianBlur方法外,Imgproc类还提供其他方法。他们简要描述-
Sr.No. | Method & Description |
---|---|
1 |
cvtColor(Mat src, Mat dst, int code, int dstCn) It converts an image from one color space to another. |
2 |
dilate(Mat src, Mat dst, Mat kernel) It dilates an image by using a specific structuring element. |
3 |
equalizeHist(Mat src, Mat dst) It equalizes the histogram of a grayscale image. |
4 |
filter2D(Mat src, Mat dst, int depth, Mat kernel, Point anchor, double delta) It convolves an image with the kernel. |
5 |
GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX) It blurs an image using a Gaussian filter. |
6 |
integral(Mat src, Mat sum) It calculates the integral of an image. |
以下示例演示了如何使用Imgproc和Core类对图像应用锐化-
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;
public class Main {
public static void main( String[] args ) {
try{
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Mat source = Highgui.imread("digital_image_processing.jpg",
Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(),source.cols(),source.type());
Imgproc.GaussianBlur(source, destination, new Size(0,0), 10);
Core.addWeighted(source, 1.5, destination, -0.5, 0, destination);
Highgui.imwrite("sharp.jpg", destination);
} catch (Exception e) {
}
}
}
当您执行给定的代码时,将看到以下输出-