0

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;    }   }  }
khan
  • 531
  • 6
  • 29

1 Answers1

1

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;
Haris
  • 13,645
  • 12
  • 90
  • 121
  • I tried the same ROI_X+R.x, i mean the rowsInd + x and colsInd+y but still it gives error – khan Apr 03 '14 at 12:50
  • cv::Rect(colsInd,rowsInd,receptiveField,receptiveField)); We have to give first x or y ? i mean rowsInd or colInd? – khan Apr 03 '14 at 12:57
  • 1
    In Mat cols always in x direction and rows always on y direction. – Haris Apr 03 '14 at 16:26