opencv_19_图像直方图

1)void histogram_demo(Mat& image);

2)void ColorInvert::histogram_demo(Mat& image) {

std::vector<Mat>bgr_plane;

split(image, bgr_plane);

const int channels[1] = { 0 };

const int bins[1] = { 256 };

float hranges[2] = { 0,255 };

const float* ranges[1] = { hranges };

Mat b_hist;

Mat g_hist;

Mat r_hist;

calcHist(&bgr_plane[0], 1, 0, Mat(), b_hist, 1, bins, ranges);

calcHist(&bgr_plane[1], 1, 0, Mat(), g_hist, 1, bins, ranges);

calcHist(&bgr_plane[2], 1, 0, Mat(), r_hist, 1, bins, ranges);

int hist_w = 512;

int hist_h = 400;

int bin_w = cvRound((double)hist_w / bins[0]);

Mat histImage = Mat::zeros(hist_h, hist_w, CV_8UC3);

normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

for (int i = 1; i < bins[0]; i++)

{

line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w * (i),hist_h-cvRound(b_hist.at<float>(i))),Scalar(255,0,0),2,8,0);

line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w * (i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0);

line(histImage, Point(bin_w * (i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))), Point(bin_w * (i), hist_h - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0), 2, 8, 0);

}

namedWindow("Histogram Demo", WINDOW_AUTOSIZE);

imshow("Histogram Demo", histImage);

}

直方图:

相关推荐
逄逄不是胖胖2 小时前
《动手学深度学习》-55-2RNN的简单实现
人工智能·深度学习
冰菓Neko2 小时前
科目四刷题总结
人工智能
guizhoumen2 小时前
2026年建站系统推荐及选项指南
大数据·运维·人工智能
咚咚王者2 小时前
人工智能之核心技术 深度学习 第四章 循环神经网络(RNN)与序列模型
人工智能·rnn·深度学习
蘑菇物联2 小时前
蘑菇物联入选“预见·2026”年度双榜,以AI技术赋能制造业绿色转型!
大数据·人工智能
无忧智库2 小时前
智慧城市核心标准全景解析:从顶层设计到落地实践的深度解读(PPT)
人工智能·智慧城市
2501_942191772 小时前
【YOLOv26实战】健身器材物体检测与识别:从模型优化到实际应用
人工智能·yolo·目标跟踪
m0_466525292 小时前
东软与葫芦岛市民政局签约 共建智慧养老服务平台
大数据·人工智能
乐居生活官2 小时前
2026五大功能全面的电商软件测评:打造全链路智能运营体系
大数据·人工智能
百***35482 小时前
2026年GEO服务商选择指南:从信息过载中构建品牌清晰度
人工智能