|
|
|
@ -147,15 +147,9 @@ void Cloning::dst(const Mat& src, Mat& dest, bool invert) |
|
|
|
|
split(complex, planes2); |
|
|
|
|
|
|
|
|
|
temp = planes2[1].t(); |
|
|
|
|
dest = Mat::zeros(src.size(), CV_32F); |
|
|
|
|
temp(Rect( 0, 1, src.cols, src.rows)).copyTo(dest); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Cloning::idst(const Mat& src, Mat& dest) |
|
|
|
|
{ |
|
|
|
|
dst(src, dest, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Cloning::solve(const Mat &img, Mat& mod_diff, Mat &result) |
|
|
|
|
{ |
|
|
|
|
const int w = img.cols; |
|
|
|
@ -173,7 +167,7 @@ void Cloning::solve(const Mat &img, Mat& mod_diff, Mat &result) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
idst(res, mod_diff); |
|
|
|
|
dst(res, mod_diff, true); |
|
|
|
|
|
|
|
|
|
unsigned char * resLinePtr = result.ptr<unsigned char>(0); |
|
|
|
|
const unsigned char * imgLinePtr = img.ptr<unsigned char>(0); |
|
|
|
@ -221,9 +215,7 @@ void Cloning::poissonSolver(const Mat &img, Mat &laplacianX , Mat &laplacianY, M |
|
|
|
|
const int w = img.cols; |
|
|
|
|
const int h = img.rows; |
|
|
|
|
|
|
|
|
|
Mat lap = Mat(img.size(),CV_32FC1); |
|
|
|
|
|
|
|
|
|
lap = laplacianX + laplacianY; |
|
|
|
|
Mat lap = laplacianX + laplacianY; |
|
|
|
|
|
|
|
|
|
Mat bound = img.clone(); |
|
|
|
|
|
|
|
|
@ -264,19 +256,19 @@ void Cloning::initVariables(const Mat &destination, const Mat &binaryMask) |
|
|
|
|
|
|
|
|
|
void Cloning::computeDerivatives(const Mat& destination, const Mat &patch, const Mat &binaryMask) |
|
|
|
|
{ |
|
|
|
|
initVariables(destination,binaryMask); |
|
|
|
|
initVariables(destination, binaryMask); |
|
|
|
|
|
|
|
|
|
computeGradientX(destination,destinationGradientX); |
|
|
|
|
computeGradientY(destination,destinationGradientY); |
|
|
|
|
computeGradientX(destination, destinationGradientX); |
|
|
|
|
computeGradientY(destination, destinationGradientY); |
|
|
|
|
|
|
|
|
|
computeGradientX(patch,patchGradientX); |
|
|
|
|
computeGradientY(patch,patchGradientY); |
|
|
|
|
computeGradientX(patch, patchGradientX); |
|
|
|
|
computeGradientY(patch, patchGradientY); |
|
|
|
|
|
|
|
|
|
Mat Kernel(Size(3, 3), CV_8UC1); |
|
|
|
|
Kernel.setTo(Scalar(1)); |
|
|
|
|
erode(binaryMask, binaryMask, Kernel, Point(-1,-1), 3); |
|
|
|
|
|
|
|
|
|
binaryMask.convertTo(binaryMaskFloat,CV_32FC1,1.0/255.0); |
|
|
|
|
binaryMask.convertTo(binaryMaskFloat, CV_32FC1, 1.0/255.0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Cloning::scalarProduct(Mat mat, float r, float g, float b) |
|
|
|
@ -305,11 +297,8 @@ void Cloning::arrayProduct(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& resu |
|
|
|
|
|
|
|
|
|
void Cloning::poisson(const Mat &destination) |
|
|
|
|
{ |
|
|
|
|
Mat laplacianX = Mat(destination.size(),CV_32FC3); |
|
|
|
|
Mat laplacianY = Mat(destination.size(),CV_32FC3); |
|
|
|
|
|
|
|
|
|
laplacianX = destinationGradientX + patchGradientX; |
|
|
|
|
laplacianY = destinationGradientY + patchGradientY; |
|
|
|
|
Mat laplacianX = destinationGradientX + patchGradientX; |
|
|
|
|
Mat laplacianY = destinationGradientY + patchGradientY; |
|
|
|
|
|
|
|
|
|
computeLaplacianX(laplacianX,laplacianX); |
|
|
|
|
computeLaplacianY(laplacianY,laplacianY); |
|
|
|
@ -331,8 +320,8 @@ void Cloning::evaluate(const Mat &I, const Mat &wmask, const Mat &cloned) |
|
|
|
|
|
|
|
|
|
wmask.convertTo(binaryMaskFloatInverted,CV_32FC1,1.0/255.0); |
|
|
|
|
|
|
|
|
|
arrayProduct(destinationGradientX,binaryMaskFloatInverted, destinationGradientX); |
|
|
|
|
arrayProduct(destinationGradientY,binaryMaskFloatInverted, destinationGradientY); |
|
|
|
|
arrayProduct(destinationGradientX, binaryMaskFloatInverted, destinationGradientX); |
|
|
|
|
arrayProduct(destinationGradientY, binaryMaskFloatInverted, destinationGradientY); |
|
|
|
|
|
|
|
|
|
poisson(I); |
|
|
|
|
|
|
|
|
@ -351,8 +340,8 @@ void Cloning::normalClone(const Mat &destination, const Mat &patch, const Mat &b |
|
|
|
|
switch(flag) |
|
|
|
|
{ |
|
|
|
|
case NORMAL_CLONE: |
|
|
|
|
arrayProduct(patchGradientX,binaryMaskFloat, patchGradientX); |
|
|
|
|
arrayProduct(patchGradientY,binaryMaskFloat, patchGradientY); |
|
|
|
|
arrayProduct(patchGradientX, binaryMaskFloat, patchGradientX); |
|
|
|
|
arrayProduct(patchGradientY, binaryMaskFloat, patchGradientY); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case MIXED_CLONE: |
|
|
|
@ -392,7 +381,7 @@ void Cloning::normalClone(const Mat &destination, const Mat &patch, const Mat &b |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case MONOCHROME_TRANSFER: |
|
|
|
|
Mat gray = Mat(patch.size(),CV_8UC1); |
|
|
|
|
Mat gray; |
|
|
|
|
cvtColor(patch, gray, COLOR_BGR2GRAY ); |
|
|
|
|
|
|
|
|
|
computeGradientX(gray,patchGradientX); |
|
|
|
@ -429,7 +418,7 @@ void Cloning::illuminationChange(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, flo |
|
|
|
|
arrayProduct(patchGradientX,binaryMaskFloat, patchGradientX); |
|
|
|
|
arrayProduct(patchGradientY,binaryMaskFloat, patchGradientY); |
|
|
|
|
|
|
|
|
|
Mat mag = Mat(I.size(),CV_32FC3); |
|
|
|
|
Mat mag; |
|
|
|
|
magnitude(patchGradientX,patchGradientY,mag); |
|
|
|
|
|
|
|
|
|
Mat multX, multY, multx_temp, multy_temp; |
|
|
|
@ -457,11 +446,10 @@ void Cloning::textureFlatten(Mat &I, Mat &mask, Mat &wmask, float low_threshold, |
|
|
|
|
{ |
|
|
|
|
computeDerivatives(I,mask,wmask); |
|
|
|
|
|
|
|
|
|
Mat out = Mat(mask.size(),CV_8UC1); |
|
|
|
|
Mat out; |
|
|
|
|
Canny(mask,out,low_threshold,high_threshold,kernel_size); |
|
|
|
|
|
|
|
|
|
Mat zeros(patchGradientX.size(), CV_32FC3); |
|
|
|
|
zeros.setTo(0); |
|
|
|
|
Mat zeros = Mat::zeros(patchGradientX.size(), CV_32FC3); |
|
|
|
|
Mat zerosMask = (out != 255); |
|
|
|
|
zeros.copyTo(patchGradientX, zerosMask); |
|
|
|
|
zeros.copyTo(patchGradientY, zerosMask); |
|
|
|
|