user2335610
user2335610

Reputation: 1

The average histogram of several histograms

I calculated H-S Histograms (using opencv) of 100 images for the same object which located in different environment conditions, I need now one average histogram of these 100 histograms!

Thank you in advance

 // we compute the histogram from the 0-th and 1-st channels
    int channels[] = {0, 1};

    calcHist( &hsv, 1, channels, Mat(), // do not use mask
             hist, 2, histSize, ranges,
             true, // the histogram is uniform
             false );
    double maxVal=0;
    minMaxLoc(hist, 0, &maxVal, 0, 0);

    int scale = 10;
    Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3);

    for( int h = 0; h < hbins; h++ )
        for( int s = 0; s < sbins; s++ )
        {
            float binVal = hist.at<float>(h, s);
            int intensity = cvRound(binVal*255/maxVal);
            rectangle( histImg, Point(h*scale, s*scale),
                        Point( (h+1)*scale - 1, (s+1)*scale - 1),
                        Scalar::all(intensity),
                        CV_FILLED );
        }

Upvotes: 0

Views: 939

Answers (2)

user2335610
user2335610

Reputation: 1

I did the work by accessing the first bin in hist1, then the first bin in hist2, ....,first bin in hist 100 and find the average of first bins, and so looping for all other 3000 bins (h_bins*S_bins=3000)

finally I get one average histogram and it works fine for advance proccedures

Upvotes: 0

Radu Diță
Radu Diță

Reputation: 14211

You could try using addWeighted and go through the array of histograms.

You can set the first weight to 1 and the second one to 1/100.0, and also have your final histogram array use float as the underlaying type.

Upvotes: 1

Related Questions