From 7e4dea968cdddc6e527deb5d72a9d381c8919843 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Wed, 19 Feb 2014 16:32:17 +0400 Subject: [PATCH] Fixed typo with indexes in getGradient(x/y) functions. --- modules/photo/src/seamless_cloning.hpp | 59 +++++++------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/modules/photo/src/seamless_cloning.hpp b/modules/photo/src/seamless_cloning.hpp index 73d719c1ba..143d550894 100644 --- a/modules/photo/src/seamless_cloning.hpp +++ b/modules/photo/src/seamless_cloning.hpp @@ -79,61 +79,34 @@ class Cloning void Cloning::getGradientx( const Mat &img, Mat &gx) { - int w = img.size().width; - int h = img.size().height; - int channel = img.channels(); - for(int i=0;i(i,j*channel+c) = - (float)img.at(i,(j+1)*channel+c) - (float)img.at(i,j*channel+c); - } - + Mat kernel = Mat::zeros(1, 3, CV_8S); + kernel.at(0,2) = 1; + kernel.at(0,1) = -1; + filter2D(img, gx, CV_32F, kernel); } void Cloning::getGradienty( const Mat &img, Mat &gy) { - int w = img.size().width; - int h = img.size().height; - int channel = img.channels(); - for(int i=0;i(i,j*channel+c) = - (float)img.at((i+1),j*channel+c) - (float)img.at(i,j*channel+c); - - } + Mat kernel = Mat::zeros(3, 1, CV_8S); + kernel.at(2,0) = 1; + kernel.at(1,0) = -1; + filter2D(img, gy, CV_32F, kernel); } void Cloning::lapx( const Mat &img, Mat &gxx) { - int w = img.size().width; - int h = img.size().height; - int channel = img.channels(); - for(int i=0;i(i,(j+1)*channel+c) = - (float)img.at(i,(j+1)*channel+c) - (float)img.at(i,j*channel+c); - } + Mat kernel = Mat::zeros(1, 3, CV_8S); + kernel.at(0,0) = -1; + kernel.at(0,1) = 1; + filter2D(img, gxx, CV_32F, kernel); } void Cloning::lapy( const Mat &img, Mat &gyy) { - int w = img.size().width; - int h = img.size().height; - int channel = img.channels(); - for(int i=0;i(i+1,j*channel+c) = - (float)img.at((i+1),j*channel+c) - (float)img.at(i,j*channel+c); - - } + Mat kernel = Mat::zeros(3, 1, CV_8S); + kernel.at(0,0) = -1; + kernel.at(1,0) = 1; + filter2D(img, gyy, CV_32F, kernel); } void Cloning::dst(double *mod_diff, double *sineTransform,int h,int w)