Question

i am trying to select a 3x3 non overlapping region of interest from an image, and than select the maximum of that 3x3, than process it. After processing now i want to save the new processed value in the original image pixel location from where the max was selected not in ROI area of 3x3. I am trying but can't do it correctly. minMaxLoc give max value location but that is in 3x3 region not in original image, Can any body help. Will be thankful.

int totalRowsMAx = totalRows-receptiveField+1;
for(int rowsInd=0;rowsInd<totalRowsMAx;rowsInd+=receptiveField){
int jj=0;
int totalColsMAx = totalCols-receptiveField+1;
for(int colsInd=0;colsInd<totalColsMAx;colsInd+=receptiveField){                       
    Mat imgROI1 = img1(cv::Rect(colsInd,rowsInd,receptiveField,receptiveField));
        if(maxpooling==true){
          minMaxLoc( imgROI1, &minVal, &maxVal, &minLoc, &maxLoc );
          cout<<"maxVa adress with and sign "<<&maxLoc<<endl;
          cout<<"maxValue in ROI"<<imgROI1.at<double>(maxLoc)<<endl;
          cout<<"maxValue address without and sign"<<maxLoc<<endl;
          cout<<"maxValue in full image "<<img1.at<double>(maxLoc)<<endl;    }   }  }
Was it helpful?

Solution

You are using ROI to select 3X3 region, then why don’t you use the same ROI to set pixel.

For example

Mat src;//source image
Rect R(x,y,W,H); //ROI rect
Mat ROI=src(R);

getminmaxonROI() //get your minmax

suppose you got minimax location like ROI_X and ROI_Y and in your source image it will be like,

SRC_X=ROI_X+R.x;
SRC_Y=ROI_Y+R.y;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top