Commit a361cc94 authored by Adrien BAK's avatar Adrien BAK

remove some more useless buffers and rename a bunch of variables

parent 61fe623c
...@@ -60,10 +60,10 @@ namespace cv ...@@ -60,10 +60,10 @@ namespace cv
protected: protected:
void init_var(const cv::Mat &I, const cv::Mat &wmask); void init_var(const cv::Mat &destination, const cv::Mat &binaryMask);
void compute_derivatives(const cv::Mat &destination, const cv::Mat &patch, const cv::Mat &binaryMask); void compute_derivatives(const cv::Mat &destination, const cv::Mat &patch, const cv::Mat &binaryMask);
void scalar_product(cv::Mat mat, float r, float g, float b); void scalar_product(cv::Mat mat, float r, float g, float b);
void poisson(const cv::Mat &destination, const cv::Mat &gx, const cv::Mat &gy, const cv::Mat &sx, const cv::Mat &sy); void poisson(const cv::Mat &destination);
void evaluate(const cv::Mat &I, const cv::Mat &wmask, const cv::Mat &cloned); void evaluate(const cv::Mat &I, const cv::Mat &wmask, const cv::Mat &cloned);
void dst(double *mod_diff, double *sineTransform,int h,int w); void dst(double *mod_diff, double *sineTransform,int h,int w);
void idst(double *mod_diff, double *sineTransform,int h,int w); void idst(double *mod_diff, double *sineTransform,int h,int w);
...@@ -79,7 +79,7 @@ namespace cv ...@@ -79,7 +79,7 @@ namespace cv
void computeLaplacianY(const cv::Mat &img, cv::Mat &gyy); void computeLaplacianY(const cv::Mat &img, cv::Mat &gyy);
private: private:
std::vector <cv::Mat> rgb_channel, rgbx_channel, rgby_channel, output; std::vector <cv::Mat> rgbx_channel, rgby_channel, output;
cv::Mat destinationGradientX, destinationGradientY; cv::Mat destinationGradientX, destinationGradientY;
cv::Mat patchGradientX, patchGradientY; cv::Mat patchGradientX, patchGradientY;
cv::Mat binaryMaskFloat, binaryMaskFloatInverted; cv::Mat binaryMaskFloat, binaryMaskFloatInverted;
......
...@@ -65,20 +65,20 @@ void Cloning::computeGradientY( const Mat &img, Mat &gy) ...@@ -65,20 +65,20 @@ void Cloning::computeGradientY( const Mat &img, Mat &gy)
filter2D(img, gy, CV_32F, kernel); filter2D(img, gy, CV_32F, kernel);
} }
void Cloning::computeLaplacianX( const Mat &img, Mat &gxx) void Cloning::computeLaplacianX( const Mat &img, Mat &laplacianX)
{ {
Mat kernel = Mat::zeros(1, 3, CV_8S); Mat kernel = Mat::zeros(1, 3, CV_8S);
kernel.at<char>(0,0) = -1; kernel.at<char>(0,0) = -1;
kernel.at<char>(0,1) = 1; kernel.at<char>(0,1) = 1;
filter2D(img, gxx, CV_32F, kernel); filter2D(img, laplacianX, CV_32F, kernel);
} }
void Cloning::computeLaplacianY( const Mat &img, Mat &gyy) void Cloning::computeLaplacianY( const Mat &img, Mat &laplacianY)
{ {
Mat kernel = Mat::zeros(3, 1, CV_8S); Mat kernel = Mat::zeros(3, 1, CV_8S);
kernel.at<char>(0,0) = -1; kernel.at<char>(0,0) = -1;
kernel.at<char>(1,0) = 1; kernel.at<char>(1,0) = 1;
filter2D(img, gyy, CV_32F, kernel); filter2D(img, laplacianY, CV_32F, kernel);
} }
void Cloning::dst(double *mod_diff, double *sineTransform,int h,int w) void Cloning::dst(double *mod_diff, double *sineTransform,int h,int w)
...@@ -270,17 +270,17 @@ void Cloning::solve(const Mat &img, double *mod_diff, Mat &result) ...@@ -270,17 +270,17 @@ void Cloning::solve(const Mat &img, double *mod_diff, Mat &result)
delete [] img_d; delete [] img_d;
} }
void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result) void Cloning::poisson_solver(const Mat &img, Mat &laplacianX , Mat &laplacianY, Mat &result)
{ {
int w = img.size().width; const int w = img.size().width;
int h = img.size().height; const int h = img.size().height;
unsigned long int idx; unsigned long int idx;
Mat lap = Mat(img.size(),CV_32FC1); Mat lap = Mat(img.size(),CV_32FC1);
lap = gxx + gyy; lap = laplacianX + laplacianY;
Mat bound = img.clone(); Mat bound = img.clone();
...@@ -324,17 +324,15 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result) ...@@ -324,17 +324,15 @@ void Cloning::poisson_solver(const Mat &img, Mat &gxx , Mat &gyy, Mat &result)
delete [] boundary_point; delete [] boundary_point;
} }
void Cloning::init_var(const Mat &I, const Mat &wmask) void Cloning::init_var(const Mat &destination, const Mat &binaryMask)
{ {
destinationGradientX = Mat(I.size(),CV_32FC3); destinationGradientX = Mat(destination.size(),CV_32FC3);
destinationGradientY = Mat(I.size(),CV_32FC3); destinationGradientY = Mat(destination.size(),CV_32FC3);
patchGradientX = Mat(I.size(),CV_32FC3); patchGradientX = Mat(destination.size(),CV_32FC3);
patchGradientY = Mat(I.size(),CV_32FC3); patchGradientY = Mat(destination.size(),CV_32FC3);
split(I,rgb_channel); binaryMaskFloat = Mat(binaryMask.size(),CV_32FC1);
binaryMaskFloatInverted = Mat(binaryMask.size(),CV_32FC1);
binaryMaskFloat = Mat(wmask.size(),CV_32FC1);
binaryMaskFloatInverted = Mat(wmask.size(),CV_32FC1);
} }
void Cloning::compute_derivatives(const Mat& destination, const Mat &patch, const Mat &binaryMask) void Cloning::compute_derivatives(const Mat& destination, const Mat &patch, const Mat &binaryMask)
...@@ -378,28 +376,26 @@ void Cloning::array_product(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& res ...@@ -378,28 +376,26 @@ void Cloning::array_product(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& res
merge(result_channels,result); merge(result_channels,result);
} }
void Cloning::poisson(const Mat &destination, const Mat &gx, const Mat &gy, const Mat &sx, const Mat &sy) void Cloning::poisson(const Mat &destination)
{ {
Mat fx = Mat(destination.size(),CV_32FC3); Mat laplacianX = Mat(destination.size(),CV_32FC3);
Mat fy = Mat(destination.size(),CV_32FC3); Mat laplacianY = Mat(destination.size(),CV_32FC3);
fx = gx + sx;
fy = gy + sy;
Mat gxx = Mat(destination.size(),CV_32FC3); laplacianX = destinationGradientX + patchGradientX;
Mat gyy = Mat(destination.size(),CV_32FC3); laplacianY = destinationGradientY + patchGradientY;
computeLaplacianX(fx,gxx); computeLaplacianX(laplacianX,laplacianX);
computeLaplacianY(fy,gyy); computeLaplacianY(laplacianY,laplacianY);
split(gxx,rgbx_channel); split(laplacianX,rgbx_channel);
split(gyy,rgby_channel); split(laplacianY,rgby_channel);
split(destination,output); split(destination,output);
poisson_solver(rgb_channel[2],rgbx_channel[2], rgby_channel[2],output[2]); for(int chan = 0 ; chan < 3 ; ++chan)
poisson_solver(rgb_channel[1],rgbx_channel[1], rgby_channel[1],output[1]); {
poisson_solver(rgb_channel[0],rgbx_channel[0], rgby_channel[0],output[0]); poisson_solver(output[chan], rgbx_channel[chan], rgby_channel[chan], output[chan]);
}
} }
void Cloning::evaluate(const Mat &I, const Mat &wmask, const Mat &cloned) void Cloning::evaluate(const Mat &I, const Mat &wmask, const Mat &cloned)
...@@ -411,7 +407,7 @@ void Cloning::evaluate(const Mat &I, const Mat &wmask, const Mat &cloned) ...@@ -411,7 +407,7 @@ void Cloning::evaluate(const Mat &I, const Mat &wmask, const Mat &cloned)
array_product(destinationGradientX,binaryMaskFloatInverted, destinationGradientX); array_product(destinationGradientX,binaryMaskFloatInverted, destinationGradientX);
array_product(destinationGradientY,binaryMaskFloatInverted, destinationGradientY); array_product(destinationGradientY,binaryMaskFloatInverted, destinationGradientY);
poisson(I,destinationGradientX,destinationGradientY,patchGradientX,patchGradientY); poisson(I);
merge(output,cloned); merge(output,cloned);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment