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

}

直方图:

相关推荐
爱学习的程序媛1 分钟前
在线客服系统技术全解析:架构、交互与数据格式
人工智能·架构·系统架构·智能客服·在线客服
实在智能RPA7 分钟前
Agent上线后有专人运营支持吗?深度解析AI Agent的全生命周期运维保障体系
运维·人工智能·ai
韦东东8 分钟前
RAGFlow v0.19图文混排:详细拆解+预处理增强案例
人工智能·大模型·agent·ragflow·图文混排
七夜zippoe11 分钟前
模型部署优化:ONNX与TensorRT实战——从训练到推理的完整优化链路
人工智能·python·tensorflow·tensorrt·onnx
AIArchivist12 分钟前
AI医院智联中枢:重构医疗生态的超级大脑,从共识到落地的全维度解析
人工智能·重构
maxmaxma14 分钟前
ROS2 机器人 少年创客营:Day 7
人工智能·python·机器人·ros2
ai生成式引擎优化技术14 分钟前
---从黑盒死穴到合规重构:论自研大模型GEO的必然终结与TS概率化递推的唯一出路
人工智能
沉木渡香21 分钟前
【AI协作开发实践指南:从25%到50%+效率提升的实战方法论】编程领域
人工智能·ai编程·最佳实践·工程化·开发效率·前后端协作
前端摸鱼匠22 分钟前
【AI大模型春招面试题14】前馈网络(FFN)在Transformer中的作用?为何其维度通常大于注意力维度?
网络·人工智能·ai·面试·大模型·transformer
披着羊皮不是狼24 分钟前
CNN卷积输出尺寸计算(公式+实例)
人工智能·神经网络·cnn