24. Histogram equalization

1. Main content

  • What is a histogram (Historgram)
  • Histogram equalization
  • API description

2. What is a histogram

  • Example
    Suppose there is image data 8x8, pixel value range 0 ~ 14 a total of 15 gray levels, the number of occurrences and histogram of each level are statistically obtained as shown in
    Insert picture description here
    the figure below.
    Insert picture description here
  • The image histogram refers to the frequency value of the pixel value (0-255) of the entire image in the gray scale range. The histogram generated accordingly is called the image histogram-histogram. The histogram reflects the distribution of image grayscale. Is the statistical feature of the image.

3. Image histogram (is a method to improve image contrast, stretch the image gray value range)

  • Original image
    Insert picture description here
  • The effect after histogram equalization
  • Histogram equalization is a method to improve the contrast of the image, stretch the gray value range of the image
    Insert picture description here

  • How to achieve the histogram equalization How to achieve, through remap in the previous lesson, we know that we can map the image gray distribution from one distribution to another distribution, and then get the mapped pixel value.
    formula:
    Insert picture description here
    Insert picture description here

4. API description

equalizeHist(
    InputArray src,//输入图像,必须是8-bit的单通道图像
    OutputArray dst// 输出结果
)

5. Demo code

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

using namespace  std;
using namespace cv;

int main(int argc,char ** argv) {
	Mat src, dst;
	src = imread("G:\\opencvTests\\C2.png");
	if (src.empty())
	{
		cout << "Could not  find this photo" << endl;
		return -1;
	}
	namedWindow("input", CV_WINDOW_AUTOSIZE);
	imshow("input",src);
	
   cvtColor(src,dst,CV_BGR2GRAY);
   equalizeHist(dst,dst);
   imshow("output",dst);

	waitKey(0);
	return 0;
}
Published 66 original articles · won praise 53 · views 6812

Guess you like

Origin blog.csdn.net/qq_43367829/article/details/105424690