This is my first blog. I wrote a grayscale histogram equalization implemented by opencv.
Please indicate the author and source for reprinting. Thank you!
//////////////////////////////////////// /// // Project_name: gray Image Process: hist/Time: 2012-02-14 // Author: hellmonky /////////////////////////////////////// /// // # include <opencv2/ opencv. HPP> # include <iostream> # include <math. h> using namespace STD; using namespace CV; int main (INT argc, char ** argv) {iplimage * src = cvloadimage (argv [1], cv_load_image_grayscale ); // "C: \ Users \ hellmonky \ Desktop \ leastsquaresmethod \ debug \ 1.bmp" int width = Src-> width; int Height = Src-> height; int sum = width * height; int step = Src-> widthstep; uchar * Data = (uchar *) Src-> imagedata; int hist [256] = {0 }; int calhist [256] = {0}; int ch [256] = {0}; int max1 = 0; int max2 = 0; //////////////////////////////////////// //// // calculate the input image grayscale distribution ////////////////////////////////////// /// // For (INT I = 0; I
Original grayscale image:
Corresponding histogram:
Images after histogram equalization:
Corresponding histogram:
From the two image histograms, we can see that after histogram equalization, the entire gray range is basically covered. The histogram effect after the most ideal histogram equalization should be a very even gray distribution, that is, the image is in a straight line.
The above content is for personal reference books, which can be understood on the Internet and in your own practice. If any, please leave a message. Thank you for your support!