📜  Java DIP-增强图像对比度

📅  最后修改于: 2020-12-14 05:36:42             🧑  作者: Mango


在本章中,将学习如何使用直方图均衡化来增强图像的对比度。

我们使用OpenCV函数equalizeHist()方法。可以在Imgproc软件包下找到。其语法如下-

Imgproc.equalizeHist(source, destination);

参数说明如下-

Sr.No. Parameter & Description
1

Source

It is 8-bit single channel source image.

2

Destination

It is the destination image.

除了equalizeHist()方法之外,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 ddepth, 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类增强图像的对比度-

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

public class Main {

   static int width;
   static int height;
   static double alpha = 2;
   static double beta = 50;
   
   public static void main( String[] args ) {
   
      try {
         System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
         Mat source = Highgui.imread("grayscale.jpg", 
         Highgui.CV_LOAD_IMAGE_GRAYSCALE);
         Mat destination = new Mat(source.rows(),source.cols(),source.type());
         
         Imgproc.equalizeHist(source, destination);
         Highgui.imwrite("contrast.jpg", destination);
         
      } catch (Exception e) {
         System.out.println("error: " + e.getMessage());
      }
   }
}

输出

当您执行给定的代码时,将看到以下输出-

原始图片

增强图像对比度教程

增强对比度图像

增强图像对比度教程