Java中使用OpenCV进行图像处理|S14(清晰度增强)

在本文中, 我们将学习如何使用OpenCv库增强图像的清晰度。
为了提高清晰度, 我们将使用高斯滤波器。高斯滤镜可减少图像中的噪声并使它看起来更好(或更高分辨率)。
首先, 我们需要为Java设置OpenCV, 我们建议使用eclipse进行相同的设置, 因为它易于使用和设置。http://docs.opencv.org/2.4/doc/tutorials/introduction/java_eclipse/java_eclipse.html
锐度增强所需的方法。
GaussianBlur(源, 目标, 新的Size(0, 0), sigmaX)–此方法位于OpenCv的Imgproc程序包中。
语法如下:

Imgproc.GaussianBlur(source, destination, new Size(0, 0), sigmaX) parameters: source - source image destination - destination image new Size(0, 0) - Gaussian kernel size sigmaX - Gaussian kernel standard deviation in X direction

addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst)-此方法位于OpenCv的Core程序包中。
语法如下:
Core.addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst) parameters: src1 - first input array alpha - weight of the first array elements src2 - second input array of the same size and channel number as src1 beta - weight of the second array elements gamma - scalar added to each sum dst - output array that has the same size and number of channels as the input arrays

imread()-此方法用于将图像读取为由OpenCV渲染的Mat对象。
语法如下:
Imgcodecs.imread(filename); parameters: filename: filename of the image file.If the image is in another directory whole path of image must be mentioned.

imwrite()-此方法用于将Mat对象写入图像文件。
语法如下:
Imgcodecs.imwrite(filename, mat_img); parameters: filename: filename of the image file.If the image is in another directory whole path of image must be mentioned. mat_img: resultant mat object.

package ocv; 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 Main { public static void main( String[] args ) { try { //For proper execution of native libraries //Core.NATIVE_LIBRARY_NAME must be loaded before //calling any of the opencv methods System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Input image Mat source = Imgcodecs.imread( "E://input.jpg" , Imgcodecs.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); //filtering Imgproc.GaussianBlur(source, destination, new Size( 0 , 0 ), 10 ); Core.addWeighted(source, 1.5 , destination, - 0.5 , 0 , destination); //writing output image Imgcodecs.imwrite( "E://output.jpg" , destination); } catch (Exception e) { } } }

注意:该代码无法在在线IDE中使用, 因为它需要硬盘中的图像。
输出如下:
input.jpg output.jpg Try to notice minor improvement in resolution

【Java中使用OpenCV进行图像处理|S14(清晰度增强)】如果发现任何不正确的地方, 或者想分享有关上述主题的更多信息, 请写评论。

    推荐阅读