几个直方图的平均直方图

时间:2014-04-09 13:19:10

标签: c++ opencv image-processing

我为同一个位于不同环境条件下的物体计算了100张图像的H-S直方图(使用opencv),我现在需要这100个直方图的一个平均直方图!

提前谢谢

 // 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 );
        }

2 个答案:

答案 0 :(得分:1)

您可以尝试使用addWeighted并浏览直方图数组。

您可以将第一个权重设置为1,将第二个权重设置为1 / 100.0,并将最终的直方图数组设置为使用float作为底层类型。

答案 1 :(得分:0)

我通过访问hist1中的第一个bin,然后是hist2中的第一个bin,....,在hist 100中的第一个bin,找到第一个bin的平均值,然后循环其他所有3000个bin来完成工作。 (h_bins * S_bins = 3000)

最后我得到一个平均直方图,它适用于提前过程

相关问题