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);

}

直方图:

相关推荐
Coder个人博客几秒前
Llama.cpp GGML 模块深度分析
人工智能·自动驾驶·llama
Das12 分钟前
【机器学习】02_线性模型
人工智能·机器学习
用户5191495848453 分钟前
Apache Tomcat CVE-2025-24813漏洞检测工具
人工智能·aigc
yongui478344 分钟前
基于BP_Adaboost的分类器和RBF神经网络回归的实现方法
人工智能·神经网络·回归
雨大王5125 分钟前
AI视觉检测引领汽车零部件制造迈向“智能制造”新时代
人工智能·汽车·视觉检测
梵得儿SHI6 分钟前
(第六篇)Spring AI 核心技术攻坚:多模态模型集成与全场景落地实战
人工智能·springai·多模态ai开发·whisper语音转录技术·springai的三层架构设计·prompt优化·多模态内容生成
逸尘散修10 分钟前
ollama+ngrok 窥探cursor 系统提示词
人工智能·ai编程·cursor
哦哦~92110 分钟前
人工智能与数据驱动方法加速金属材料设计与应用
人工智能·金属材料
骑士梦11 分钟前
2025 年 AI 领域关键进展
人工智能
北京理工大学软件工程13 分钟前
深度学习笔记(b站2025李宏毅课程)
人工智能·笔记·深度学习