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

}

直方图:

相关推荐
DP DPharness8 分钟前
拆开 webnovel-writer 的 Story System:从运行时合同到投影重放
人工智能·dpharness
素男20 分钟前
叫沉默的,和叫留白的——一次改名记
人工智能·agent·self-becoming·ai长期记忆·ai自我介绍
IT古董21 分钟前
《FDE前沿部署工程师实战教程》23 - Enterprise AI Event Bus:事件驱动、消息队列与AI工作流自动触发
大数据·数据库·人工智能
枫叶丹424 分钟前
AI 的记忆不是数据库:长期个性化如何避免过期与污染
人工智能·chatgpt·开源·agent·codex
阿尔法工场研究院26 分钟前
宇树们不想重蹈新造车的覆辙
大数据·人工智能·科技·机器人
程序员JerrySUN32 分钟前
Jetson边缘嵌入式实战课程第四讲:用 Yocto 定制 Jetson 系统,从开发走向产品化
arm开发·人工智能·安全·计算机视觉·目标跟踪
程序员cxuan32 分钟前
DeepSeek Harness 出了桌面端?我把它扒了一遍
人工智能·后端·程序员
这张生成的图像能检测吗38 分钟前
(论文速读)DI-CDM:微调条件扩散模型在结构健康监测中的损伤成像
人工智能·lora·扩散模型·高分辨率成像·结构健康监测
阿伟玩不懂40 分钟前
接入第一个 MCP Server:让 AI 自己看你的数据库
ide·人工智能
中电金信41 分钟前
中电金信参编的团体标准《商业银行应用程序接口治理能力要求》正式发布
大数据·运维·人工智能