opencv (二十六)图像直方图匹配

小白学视觉,笔记,扩展

直方图均衡化,将原图的直方图分布更均匀

直方图匹配,将直方图调整集中在某个区域
opencv (二十六)图像直方图匹配_第1张图片

#include 
#include 

using namespace cv;
using namespace std;

void drawHist(Mat& hist, int type, string name)  //归一化并绘制直方图函数
{
	int hist_w = 512;
	int hist_h = 400;
	int width = 2;
	Mat histImage = Mat::zeros(hist_h, hist_w, CV_8UC3);
	normalize(hist, hist, 1, 0, type, -1, Mat());
	for (int i = 1; i <= hist.rows; i++)
	{
		rectangle(histImage, Point(width * (i - 1), hist_h - 1),
			Point(width * i - 1, hist_h - cvRound(20 * hist_h * hist.at(i - 1)) - 1),
			Scalar(255, 255, 255), -1);
	}
	imshow(name, histImage);
}
//主函数
int main()
{
	Mat img1 = imread(

你可能感兴趣的:(OpenCV,C++,opencv,计算机视觉,人工智能)