Opencv histogram equalization

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.