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

}

直方图:

相关推荐
wjykp1 天前
part 3神经网络的学习
人工智能·神经网络·学习
core5121 天前
【硬核测评】Gemini 3 编程能力全面进化:不仅仅是 Copilot,更是你的 AI 架构师
人工智能·编程·copilot
jieshenai1 天前
llamafactory SFT 从断点恢复训练
人工智能
微风企1 天前
杭州上城区CID青年企业家创新学院启航!微风企助力AI建设与青年创业成长
人工智能
chataipaper0021 天前
10款免费降ai率工具合集,轻松搞定论文降AIGC!【2025学姐亲测】
人工智能·深度学习·aigc·降ai·论文ai率
一见已难忘1 天前
昇腾加持下的Llama 3.2:开源大模型推理性能1B英文原版与3B中文微调模型实测对比
人工智能·开源·llama·gitcode·昇腾
CV-杨帆1 天前
使用LLaMA-Factory微调训练Qwen2-VL-7B/Qwen2.5-VL-7B/Qwen3-VL-2B与视觉大模型数据集制作流程与训练评估
人工智能
stjiejieto1 天前
AI 生成内容(AIGC)版权归属引争议:创作者、平台、AI 公司,谁该拥有 “作品权”?
人工智能·aigc
网安入门学习1 天前
2025年AIGC人才需求报告:从招聘数据看行业趋势与技能要求
人工智能·windows·ai作画·stable diffusion·aigc
winner88811 天前
扩散模型(Diffusion Model)详解:从原理、U-Net结构到生成机制
人工智能