OpenCv 018 --- image histogram equalization

1 prepared before knowledge

  Histogram equalization can be used for image enhancement, the image histogram equalization, can improve the accuracy of a subsequent object detection, medical imaging images, satellite images, machine vision image can be an image by histogram equalization enhance the quality, contrast enhancement.

2 used mainly OpenCv API

CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst );

/** @brief Equalizes the histogram of a grayscale image.

The function equalizes the histogram of the input image using the following algorithm:

- Calculate the histogram \f$H\f$ for src .
- Normalize the histogram so that the sum of histogram bins is 255.
- Compute the integral of the histogram:
\f[H'_i = \sum _{0 \le j < i} H(j)\f]
- Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$

The algorithm normalizes the brightness and increases the contrast of the image.

@param src Source 8-bit single channel image.
@param dst Destination image of the same size and type as src .
*/

3 program code

#include <opencv2\opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    Mat src = imread("G:\\CVworkstudy\\program_wwx\\Research society140\\ZhaiZhigang140\\colormap.png");
    if (src.empty())
    {
        printf("Could not load image...\n");
        return -1;
    }
    namedWindow("input", WINDOW_AUTOSIZE);
    Mat gray, dst;
    cvtColor(src, gray, COLOR_BGR2GRAY);
    imshow("input", gray);
    equalizeHist(gray, dst);
    imshow("eq", dst);

    waitKey(0);
    return 0;
}

4 run results

5 Expansion and precautions

null

Guess you like

Origin www.cnblogs.com/Vince-Wu/p/11402906.html