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

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++)
        int maxIndex=0, maxCount=0;
        int index;
        for(int n=0;n<imgs.size();n++)
            index = imgs[n].at<uchar>(i,j);
            if(count[index] > maxCount)
                maxCount = count[index];
                maxIndex = index;
        }<uchar>(i,j) = maxIndex;

Is there other ways to compute the mode more efficient?


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.

Need Your Help

Crystal Report - Multiple Crosstabs with Different Record Selection Criteria

crystal-reports report crosstab

I’m using Crystal Report 2011 and I would like to know if it is possible to generate two crosstab tables with different record selection in the same report?

Updating Roles in rolify using ActiveAdmin

ruby-on-rails-4 activeadmin cancan rolify

Using Rails 4.0, ActiveAdmin, Rolify and CanCan, Adding and removing user roles via the activeadmin panel does not save (commit to database).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.