如果我们使用minMaxLoc函数,如何替换像素值

时间:2014-04-03 11:38:34

标签: visual-c++ opencv artificial-intelligence neural-network backpropagation

我试图从图像中选择一个3x3非重叠感兴趣区域,然后选择该3x3的最大值,而不是处理它。现在处理之后,我想将新处理的值保存在原始图像像素位置,从中选择最大值而不是在3x3的ROI区域。我正在尝试但不能正确地做到这一点。 minMaxLoc给出最大值位置但是在原始图像中的3x3区域中,任何身体都可以帮助。会感恩的。

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;    }   }  }

1 个答案:

答案 0 :(得分:1)

您正在使用ROI选择3X3区域,那么为什么不使用相同的ROI来设置像素。

例如

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

getminmaxonROI() //get your minmax

假设你有像ROI_X和ROI_Y这样的极小极大位置,并且在你的源图像中就像是,

SRC_X=ROI_X+R.x;
SRC_Y=ROI_Y+R.y;
相关问题