Access histogram data

asked 2014-04-01 07:16:46 -0600

juanmanpr gravatar image

updated 2014-04-01 07:19:53 -0600

Hello,

How do I extract actual histogram data (bin value)?. I am a bit confused, because after computing a histogram with cv::calcHist, the matrix size (rows, cols) appears to be -1,-1. However, the cv::compareHist seems to correctly tell that similar images have a small CHI2 distance, and different images have a large CHI2 value.

int bins = 4;
int histSize[] = {bins, bins, bins};
float rranges[] = { 0, 255 }, granges[] = { 0, 255 }, branges[] = { 0, 255 };
const float* ranges[] = { rranges, granges, branges };
int channels[] = {0, 1, 2};
cv::calcHist( &im, 1, channels, mask, hist, 3, histSize, ranges, true, false );

Thanks

edit retag flag offensive close merge delete

Comments

@berak, yes, I updated the question with the code I am using to compute the histograms

juanmanpr gravatar imagejuanmanpr ( 2014-04-01 07:21:06 -0600 )edit
1

since rows and cols only make sense for a 2d matrix, for higher dimensions you query the Mat.size member (not the function!). so hist.size[0] == hist.size[1] == hist.size[2] == 4;

(again, rows==-1 and cols==-1 is ok in your case)

berak gravatar imageberak ( 2014-04-01 07:32:23 -0600 )edit

I see... But then, how would it be the use of Mat::at method here? Or is it mandatory to use NAryMatIterator to get the histogram bin data?

juanmanpr gravatar imagejuanmanpr ( 2014-04-01 08:17:23 -0600 )edit