Java中的图像处理——对比度增强

先决条件:

null

对比度增强

首先,我们需要为Java设置OpenCV,我们建议使用eclipse,因为它易于使用和设置。现在让我们了解一些增强图像颜色所需的方法。现在让我们了解一下增强对比度所需的一些方法。

方法1:equalizeHist(源、目标): 此方法位于 Imgproc软件包 属于 opencv。来源 参数是一个8位单通道源图像 目的地 参数是目标图像

方法2:Imcodecs。imread()或imcodec。imwrite(): 这些方法用于读取和写入OpenCV渲染的Mat对象图像。

实施: 让我们获取任意输入图像,如下所示:

图片[1]-Java中的图像处理——对比度增强-yiteyi-C++库

例子:

JAVA

// Java Program to Demonstrate Contrast Enhancement
// Using OpenCV Library
// Importing package module
package ocv;
// Importing required classes
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
// Main class
public class GFG {
// Try block to check for exceptions
public static void main(String[] args)
{
// Try block to check for exceptions
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);
// Reading image from local directory by
// creating object of Mat class
Mat source = Imgcodecs.imread(
"E:\input.jpg" ,
Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Mat destination
= new Mat(source.rows(), source.cols(),
source.type());
// Applying histogram equalization
Imgproc.equalizeHist(source, destination);
// Writing output image to some other directory
// in local system
Imgcodecs.imwrite( "E:\output.jpg" ,
destination);
// Display message on console for successful
// execution of program
System.out.print(
"Image Successfully Contrasted" );
}
// Catch block to handle exceptions
catch (Exception e) {
// Print the exception on the console
// using getMessage() method
System.out.println( "error: " + e.getMessage());
}
}
}


输出: 在控制台上

Image Successfully Contrasted

图片[2]-Java中的图像处理——对比度增强-yiteyi-C++库

本文由 普拉蒂克·阿加瓦尔 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享