c++ - 几个直方图的平均直方图

标签 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 );
        }

最佳答案

您可以尝试使用 addWeighted并遍历直方图数组。

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

关于c++ - 几个直方图的平均直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22963811/

相关文章:

c++ - 为什么线程在终止而不分离时让它们的堆栈保持不变?

python - OpenCV 中的方向检测出现问题

c++ - 在 4-connectivity two-pass 算法中编码 union-find

c++ - 如何修复段错误(核心转储)?

c++ - 为 64 位编译 Microsoft Detours

c++ - 一种无需最大化内存即可实时缓冲高清视频的有效方法

python - 使用 OpenCV 在 Python 中计算图像中的黑色像素数

ios - 快速从 UIImage 中找到独特的颜色?

python - 使用python查找图像中黑色/灰色像素的所有坐标

c++ - 如果应用程序从具有 Windows 管理权限的 cmd 打开,则会出现访问冲突