OpenCV: compute the statistical mode of a set of cv::Mat

柔情痞子 提交于 2019-12-11 02:21:17

问题


I am using the following to obtain the statistical mode of a set of cv::Mat:

vector<Mat> imgs(30);
...
...

Mat mode = Mat::zeros(imgRows, imgCols, CV_8U);
for(int i=0;i<mode.rows;i++)
{
    for(int j=0;j<mode.cols;j++)
    {
        vector<int>count(256,0);
        int maxIndex=0, maxCount=0;
        int index;
        for(int n=0;n<imgs.size();n++)
        {
            index = imgs[n].at<uchar>(i,j);
            count[index]++;
            if(count[index] > maxCount)
            {
                maxCount = count[index];
                maxIndex = index;
            }
        }
        mode.at<uchar>(i,j) = maxIndex;
    }
}

Is there other ways to compute the mode more efficient?


回答1:


Calculate histogram and use the peak value in the histogram. You can modify the code already provided by opencv to calculate mode. This page also explains about histogram and different ways to use it.



来源:https://stackoverflow.com/questions/14474978/opencv-compute-the-statistical-mode-of-a-set-of-cvmat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!