问题
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