From 6bfea73716d0792d584fafbaa56e0f07790bd66a Mon Sep 17 00:00:00 2001 From: Adrien BAK Date: Fri, 10 Oct 2014 14:49:10 +0900 Subject: [PATCH] move calls to ptr<> --- modules/photo/src/seamless_cloning_impl.cpp | 60 +++++++++++++++++++---------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/modules/photo/src/seamless_cloning_impl.cpp b/modules/photo/src/seamless_cloning_impl.cpp index 509ce47..35c8373 100644 --- a/modules/photo/src/seamless_cloning_impl.cpp +++ b/modules/photo/src/seamless_cloning_impl.cpp @@ -87,9 +87,11 @@ void Cloning::dst(const Mat& src, Mat& dest, bool invert) for(int j = 0 ; j < src.rows ; ++j) { + float * tempLinePtr = temp.ptr(j); + const float * srcLinePtr = src.ptr(j); for(int i = 0 ; i < src.cols ; ++i) { - temp.ptr(j)[src.cols + 2 + i] = - src.ptr(j)[src.cols - 1 - i]; + tempLinePtr[src.cols + 2 + i] = - srcLinePtr[src.cols - 1 - i]; } } @@ -104,11 +106,12 @@ void Cloning::dst(const Mat& src, Mat& dest, bool invert) for(int j = 0 ; j < src.cols ; ++j) { + float * tempLinePtr = temp.ptr(j); for(int i = 0 ; i < src.rows ; ++i) { float val = planes[1].ptr(i)[j + 1]; - temp.ptr(j)[i + 1] = val; - temp.ptr(j)[temp.cols - 1 - i] = - val; + tempLinePtr[i + 1] = val; + tempLinePtr[temp.cols - 1 - i] = - val; } } @@ -140,43 +143,54 @@ void Cloning::solve(const Mat &img, std::vector& mod_diff, Mat &result) for(int j = 0 ; j < h-2; j++) { + float * resLinePtr = res.ptr(j); for(int i = 0 ; i < w-2; i++) { - res.ptr(j)[i] /= (filter_X[i] + filter_Y[j] - 4); + resLinePtr[i] /= (filter_X[i] + filter_Y[j] - 4); } } idst(res, ModDiff); + unsigned char * resLinePtr = result.ptr(0); + const unsigned char * imgLinePtr = img.ptr(0); + const float * interpLinePtr = NULL; + //first col for(int i = 0 ; i < w ; ++i) result.ptr(0)[i] = img.ptr(0)[i]; for(int j = 1 ; j < h-1 ; ++j) { + resLinePtr = result.ptr(j); + imgLinePtr = img.ptr(j); + interpLinePtr = ModDiff.ptr(j-1); + //first row - result.ptr(j)[0] = img.ptr(j)[0]; + resLinePtr[0] = imgLinePtr[0]; for(int i = 1 ; i < w-1 ; ++i) { //saturate cast is not used here, because it behaves differently from the previous implementation //most notable, saturate_cast rounds before truncating, here it's the opposite. - float value = ModDiff.ptr(j-1)[i-1]; + float value = interpLinePtr[i-1]; if(value < 0.) - result.ptr(j)[i] = 0; + resLinePtr[i] = 0; else if (value > 255.0) - result.ptr(j)[i] = 255; + resLinePtr[i] = 255; else - result.ptr(j)[i] = static_cast(value); + resLinePtr[i] = static_cast(value); } //last row - result.ptr(j)[w-1] = img.ptr(j)[w-1]; + resLinePtr[w-1] = imgLinePtr[w-1]; } //last col + resLinePtr = result.ptr(h-1); + imgLinePtr = img.ptr(h-1); for(int i = 0 ; i < w ; ++i) - result.ptr(h-1)[i] = img.ptr(h-1)[i]; + resLinePtr[i] = imgLinePtr[i]; } @@ -351,25 +365,29 @@ void Cloning::normalClone(const Mat &destination, const Mat &patch, const Mat &b for(int i=0;i < h; i++) { + float * patchXLinePtr = patchGradientX.ptr(i); + float * patchYLinePtr = patchGradientY.ptr(i); + const float * destinationXLinePtr = destinationGradientX.ptr(i); + const float * destinationYLinePtr = destinationGradientY.ptr(i); + const float * binaryMaskLinePtr = binaryMaskFloat.ptr(i); + for(int j=0; j < w; j++) { for(int c=0;c(i)[j*channel+c] - patchGradientY.ptr(i)[j*channel+c]) > - abs(destinationGradientX.ptr(i)[j*channel+c] - destinationGradientY.ptr(i)[j*channel+c])) + if(abs(patchXLinePtr[j*channel+c] - patchYLinePtr[j*channel+c]) > + abs(destinationXLinePtr[j*channel+c] - destinationYLinePtr[j*channel+c])) { - patchGradientX.ptr(i)[j*channel+c] = patchGradientX.ptr(i)[j*channel+c] - * binaryMaskFloat.ptr(i)[j]; - patchGradientY.ptr(i)[j*channel+c] = patchGradientY.ptr(i)[j*channel+c] - * binaryMaskFloat.ptr(i)[j]; + patchXLinePtr[j*channel+c] *= binaryMaskLinePtr[j]; + patchYLinePtr[j*channel+c] *= binaryMaskLinePtr[j]; } else { - patchGradientX.ptr(i)[j*channel+c] = destinationGradientX.ptr(i)[j*channel+c] - * binaryMaskFloat.ptr(i)[j]; - patchGradientY.ptr(i)[j*channel+c] = destinationGradientY.ptr(i)[j*channel+c] - * binaryMaskFloat.ptr(i)[j]; + patchXLinePtr[j*channel+c] = destinationXLinePtr[j*channel+c] + * binaryMaskLinePtr[j]; + patchGradientY.ptr(i)[j*channel+c] = destinationYLinePtr[j*channel+c] + * binaryMaskLinePtr[j]; } } } -- 2.7.4