我正在尝试从图像中选择一个3×3的非重叠感兴趣区域,然后从这个3×3区域中选择最大值,接着进行处理。处理完成后,我希望将新的处理值保存到原始图像中,从中选择最大值的像素位置,而不是在3×3的ROI区域中。我尝试过但无法正确实现。minMaxLoc函数给出的是3×3区域内的最大值位置,而不是在原始图像中的位置。能有人帮我吗?将不胜感激。
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; } } }
回答:
您使用ROI来选择3×3区域,那么为什么不使用相同的ROI来设置像素呢?
例如
Mat src;//源图像Rect R(x,y,W,H); //ROI矩形Mat ROI=src(R);getminmaxonROI() //获取您的minmax
假设您得到了minimax位置,如ROI_X和ROI_Y,在您的源图像中将是,
SRC_X=ROI_X+R.x;SRC_Y=ROI_Y+R.y;