#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

Mat img1, img2, img3, img_gray, map_x, map_y;

char win1[] = "window1";
char win2[] = "window2";
char win3[] = "window3";
char win4[] = "window4";

int threshold_value = 0;
int max_value = 255;
RNG rng(12345);

int Demo_Histogram();

int index = 0;

//Remap
int Demo_Histogram()
{
  img1 = imread("D://images//1//9.jpg");
  if (img1.empty())
  {
    cout << "could not load image..." << endl;
    return 0;
  }
  imshow(win1, img1);

  vector<Mat> bgr_planes;

  //把多通道图像分为多个单通道图像
  split(img1,bgr_planes);
  //imshow(win2,bgr_planes);
  int histSize = 256;
  float range[] = {0,256};

  const float *histRanges = {range};
  Mat b_hist, g_hist, r_hist;
  calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRanges, true, false);
  calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRanges, true, false);
  calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRanges, true, false);

  int hist_h = 400;
  int hist_w = 512;
  int bin_w = hist_w / histSize;
  Mat histImage(hist_w,hist_h,CV_8UC3,Scalar(0,0,0));

  //归一化处理
  normalize(b_hist, b_hist, 0, hist_h, NORM_MINMAX, -1, Mat());
  normalize(g_hist, g_hist, 0, hist_h, NORM_MINMAX, -1, Mat());
  normalize(r_hist, r_hist, 0, hist_h, NORM_MINMAX, -1, Mat());

  for (int i=1;i<histSize;i++)
  {
    line(histImage,
      Point((i-1)*bin_w,hist_h-cvRound(b_hist.at<float>(i-1))),
      Point((i)*bin_w, hist_h - cvRound(b_hist.at<float>(i))),
      Scalar(255,0,2),2,LINE_AA);

    line(histImage,
      Point((i - 1)*bin_w, hist_h - cvRound(g_hist.at<float>(i - 1))),
      Point((i)*bin_w, hist_h - cvRound(g_hist.at<float>(i))),
      Scalar(0, 255, 2), 2, LINE_AA);

    line(histImage,
      Point((i - 1)*bin_w, hist_h - cvRound(r_hist.at<float>(i - 1))),
      Point((i)*bin_w, hist_h - cvRound(r_hist.at<float>(i))),
      Scalar(0, 0, 255), 2, LINE_AA);
  }

  imshow(win2, histImage);
  return 0;
}

int main()
{
  Demo_Histogram();

  waitKey(0);
  return 0;
}

最新文章

  1. .NET框架解决的问题
  2. HashMap Hasptable的区别
  3. Max Points on a Line
  4. 移动端H5页面之iphone6的适配(转)
  5. Android studio 一个项目中添加两个module遇到的bug
  6. oracle replace函数
  7. 【转】Visual Studio项目相对路径的设置,实用
  8. iostream/fstream中的输入输出流指针的绑定,tie函数的使用。
  9. 17.2?Replication Implementation 复制实施:
  10. File类基本操作之OutputStream字节输出流
  11. PAT乙级--1003
  12. 微信小程序实现按首字母检索城市列表
  13. 028实现strStr()
  14. Java面试——线程池
  15. TabLoaout简单框架
  16. K均值聚类
  17. Asp:函数是用传值还是传址
  18. filebeat配置
  19. KnockoutJs学习笔记(六)
  20. [svc]centos6使用chkconfig治理服务和其原理

热门文章

  1. Oracle 之 AIO (异步io)
  2. C++直接初始化和复制初始化2
  3. easyui-datebox设置只能选择年月,设置当前月的第一天和最后一天
  4. DRF 解析器组件
  5. date.js
  6. UE4 代码总结
  7. FBString
  8. Oralce OMF 功能详解
  9. ORACLE删除字段(set unused的用法)
  10. 关于操作 ASP.NET Web API的实例