Skip to content

Instantly share code, notes, and snippets.

@hkhojasteh
Created January 30, 2019 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkhojasteh/18cfb5efd6d1fa62796ad898e434788f to your computer and use it in GitHub Desktop.
Save hkhojasteh/18cfb5efd6d1fa62796ad898e434788f to your computer and use it in GitHub Desktop.
int histSize = 140;
Mat histdata, img_sharp_not;
bitwise_not(img_sharp, img_sharp_not);
//Calculate the histograms for input image
reduce(img_sharp_not, histdata, 0, CV_REDUCE_SUM, CV_32S);
int hist_w = img.cols * 4; int hist_h = img.rows * 4;
int bin_w = cvRound((double)hist_w / histSize);
int txtMargin = 20;
Mat histImage(hist_h + txtMargin, hist_w + txtMargin, CV_8UC3, Scalar(255, 255, 255));
//Normalize the result to [ 0, histImage.rows ]
normalize(histdata, histdata, 0, histImage.rows, NORM_MINMAX, -1, Mat());
for (int i = 1; i < histSize; i++){ //Draw histogram in summary
line(histImage, Point(bin_w*(i - 1) + txtMargin, hist_h - cvRound(histdata.at<int>(i - 1))), Point(bin_w*(i) + txtMargin, hist_h - cvRound(histdata.at<int>(i))), Scalar(255, 100, 0), 2, 8, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment