1
votes

I have checked minMaxLoc but it just gives the maximum and minimum locations of the matrix. What i need to find is maximum or equal to some other digit . e.g. (abc >=7) then give all the locations from the matrix where this condition applies.

Matlab example : [a,b] = find( heMap >= (max(max(heMap)) ) );

so how can i fulfill the condition in opencv for getting the particular maximum or minimum values.? kindly help

regards

Currently i am using this way

double getMaxValue(Mat hemap)
{
MatConstIterator_<double> it = hemap.begin<double>(), it_end = hemap.end<double>();
double maxdata=0;

for(; it != it_end; ++it)
{
    if(*it>maxdata)
    {
        maxdata = *it;
    }
}

return maxdata;
}
3

3 Answers

1
votes

I don't know any built in function, that does exactly this. You can compare your matrix with an element which gives you a boolean matrix. But I don't know about any function that gives you the position of every non-zero element, like find.

But it is very simple to just loop over the array and do the comparison yourself:

int thresh = 50;
for(int y=0;y<matrix.rows; y++)
  for(int x=0;x<matrix.cols; x++)
    if( matrix.at<uchar>(y,x) >= thresh)
      printf(" (%d,%d) = %d\n",x,y, matrix.at<uchar>(y,x));
0
votes

How about cv::compare function, it compares each pixel with given number and sets the output array by 255 if the condition is satisfied else 0.

0
votes

I give you a 2+1-step solution:

  1. get maximum with minMaxLoc() -> max_val.

  2. use inRange(input, max_val, max_val, output_mask) to get all the max elements white.

  3. Decide what to do with these locations.
    Say, you can easily detect hot spots, big blobs of max-es or connected components of max-es. (with dilate and erode and then using floodFill on the spot centres, one-by-one.)