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 channels1 = { 0 };

const int bins1 = { 256 };

float hranges2 = { 0,255 };

const float* ranges1 = { hranges };

Mat b_hist;

Mat g_hist;

Mat r_hist;

calcHist(&bgr_plane0, 1, 0, Mat(), b_hist, 1, bins, ranges);

calcHist(&bgr_plane1, 1, 0, Mat(), g_hist, 1, bins, ranges);

calcHist(&bgr_plane2, 1, 0, Mat(), r_hist, 1, bins, ranges);

int hist_w = 512;

int hist_h = 400;

int bin_w = cvRound((double)hist_w / bins0);

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 < bins0; 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 分钟前
【周末消息】2026年5月30日-6月1日
大数据·人工智能·深度学习·机器学习·金融
AI导出鸭PC端2 分钟前
智谱清言清除符号:当LLM输出遭遇“结构性失序”,一份关于AI导出鸭的工程化测评
人工智能
_李小白5 分钟前
【android opencv学习笔记】Day 29: 滤波算法之Sobel 边缘检测
android·opencv·学习
Engineer邓祥浩15 分钟前
宏观认知(3):AI战略与社会影响——吴恩达《AI for Everyone》Week3学习笔记
人工智能·笔记·学习
weixin_4684668523 分钟前
图像连通域分析新手实战指南
图像处理·人工智能·深度学习·ai·机器视觉·连通域
狒狒热知识28 分钟前
中小企业品牌破局之道178软文网以轻量化传播助力软文营销从零到一
人工智能
J2虾虾30 分钟前
Spring AI Alibaba - Models 模型
人工智能·spring·microsoft
万俟淋曦35 分钟前
【论文速递】2026年第01周(Dec-28-Jan-03)(Robotics/Embodied AI/LLM)
人工智能·ai·机器人·大模型·论文·robotics·具身智能
不务正业的小主治36 分钟前
ezygene-多种算法计算免疫评分
人工智能·r语言·简析基因·ezygene·免疫分析