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

}

直方图:

相关推荐
Mintopia2 分钟前
🌐 跨平台 WebAIGC 适配:当 AI 遇上屏幕尺寸差异的爱恨情仇
人工智能·aigc·trae
天地之于壹炁兮24 分钟前
用VSCode打造高效AI开发环境:从配置到实战
ide·人工智能·vscode
孤狼warrior29 分钟前
我想拥有作家的思想 循环神经网络及变型
人工智能·rnn·深度学习·神经网络·lstm
极客BIM工作室43 分钟前
BERT模型中词汇表向量与网络权重:从属关系与不可替代的功能分工
人工智能·自然语言处理·bert
八年。。43 分钟前
Ai笔记(二)-PyTorch 中各类数据类型(numpy array、list、FloatTensor、LongTensor、Tensor)的区别
人工智能·pytorch·笔记
百***68821 小时前
开源模型应用落地-工具使用篇-Spring AI-Function Call(八)
人工智能·spring·开源
许泽宇的技术分享1 小时前
从零到一,开源大模型的“民主化“之路:一份让AI触手可及的实战宝典
人工智能·开源·大模型
文慧的科技江湖1 小时前
开源 | 企业级开源人工智能训练推理平台 - GPU池化平台 - GPU算力平台 - GPU调度平台 - AI人工智能操作系统
人工智能·开源·gpu池化·推理平台·训练平台·gpu管理平台·ai人工智能操作系统
东皇太星1 小时前
VGGNet (2014)(卷积神经网络)
人工智能·神经网络·cnn·卷积神经网络
Dev7z1 小时前
智能情感识别:基于USB摄像头和深度学习的实时面部表情分析系统
人工智能·深度学习