OpenCV Java histogram equalization





  • Histogram equalization is the pixel intensity distribution range stretching a method to enhance the image contrast.
  • Put it more clearly, to the above histogram, for example, you can see the pixels focused on some of the intensity values of the middle of the histogram equalization to do is. Stretch this range, see below left: green circle a few pixel distribution on its intensity value. after its application equalized, intermediate obtained histogram shown in FIG. equalization see below right image.

../../../../../_images/Histogram_Equalization_Theory_1.jpg

Java Code implementation:


package com.gitee.dgw.lesson8;

import com.gitee.dgw.lesson1.platformUtils;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**
 * @program: learn-opencv
 * @description:
 * @author: Mr.Dai
 * @create: 2020-03-10 18:41
 **/
public class equalizeHist {


    private final  static String path=System.getProperty("user.dir")+"\\catton.jpg";
    static{
        platformUtils.loadLibraries (); 
    } 


    public  static  void main (String [] args) { 
        Mat srcImage; 
        Mat dstimg = new new Mat ();
         // read an image
         // Image Imgcodecs.imread = (path); 

        // read take a gradation image 
        srcImage = Imgcodecs.imread (path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); 

        IF (srcimage.empty ()) { 
            System.err.println ( "load picture error check image path!" );
             return ; 
        } 

        Imgproc.equalizeHist (srcImage, dstimg); 

        // displayed on the cv :: imshow package namedWindos
        HighGui.imshow ( "dstimg showimg" , dstimg); 
        HighGui.imshow ( "srcImage showimg" , srcImage);
         // wait indefinitely key press 
        HighGui.waitKey (0 ); 

    } 
}




image

Guess you like

Origin www.cnblogs.com/dgwblog/p/12458167.html