Ask Your Question

How to create a histogram from a table of values?

asked 2012-09-29 15:37:36 -0500

501 Not Implemented gravatar image

Hi, can somebody tell me how to create a histogram from a table of values instead from a image?

I want to compare a histogram with a pattern of a gaussian function with some images.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-09-30 03:09:57 -0500

Kirill Kornyakov gravatar image

You can create a matrix from you "table of values" and then call cv::calcHist on this matrix, because OpenCV can build histograms for CV_8U and CV_32F types. Here is how you can create a matrix from an array of floats:

float* Idata=new float[480*640*3];
Mat I(480, 640, CV_32FC3, Idata);

More examples in the OpenCV Cheatsheet. And you can always build a Mat on top of std::vector.

edit flag offensive delete link more


Oh, I thought there is some method to create histogram which based on some datas for the bins. (a table from 0-255 with values from 0.0 to 1.0)

501 Not Implemented gravatar image501 Not Implemented ( 2012-10-04 07:51:08 -0500 )edit

not sure if this was what you were asking about with the bins but you can specify whether to have either uniform of custom bins, as a flag in the cv::calcHist method. Then you just input a float array with the lowest inclusive value(will be included), then all of the top exclusive boundaries of your bins(so that bin will not include values from that value).

i.e: float exampleArray[] = {0, 100, 256};

So this will have two bins, the first from 0-99 and the second from 100-255.

Also remember to input the correct number of bins and the non-uniform flag in the cv::calcHist method.

Hope this helps you or others with similar problems.

albertJ gravatar imagealbertJ ( 2015-07-24 08:37:08 -0500 )edit

Question Tools


Asked: 2012-09-29 15:37:36 -0500

Seen: 317 times

Last updated: Sep 30 '12