coding guidelines
This commit is contained in:
@@ -116,7 +116,7 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point
|
|||||||
|
|
||||||
|
|
||||||
Cloning obj;
|
Cloning obj;
|
||||||
obj.normal_clone(dest,cd_mask,dst_mask,blend,flags);
|
obj.normalClone(dest,cd_mask,dst_mask,blend,flags);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ void cv::colorChange(InputArray _src, InputArray _mask, OutputArray _dst, float
|
|||||||
src.copyTo(cs_mask,gray);
|
src.copyTo(cs_mask,gray);
|
||||||
|
|
||||||
Cloning obj;
|
Cloning obj;
|
||||||
obj.local_color_change(src,cs_mask,gray,blend,red,green,blue);
|
obj.localColorChange(src,cs_mask,gray,blend,red,green,blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::illuminationChange(InputArray _src, InputArray _mask, OutputArray _dst, float a, float b)
|
void cv::illuminationChange(InputArray _src, InputArray _mask, OutputArray _dst, float a, float b)
|
||||||
@@ -168,7 +168,7 @@ void cv::illuminationChange(InputArray _src, InputArray _mask, OutputArray _dst,
|
|||||||
src.copyTo(cs_mask,gray);
|
src.copyTo(cs_mask,gray);
|
||||||
|
|
||||||
Cloning obj;
|
Cloning obj;
|
||||||
obj.illum_change(src,cs_mask,gray,blend,alpha,beta);
|
obj.illuminationChange(src,cs_mask,gray,blend,alpha,beta);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,5 +193,5 @@ void cv::textureFlattening(InputArray _src, InputArray _mask, OutputArray _dst,
|
|||||||
src.copyTo(cs_mask,gray);
|
src.copyTo(cs_mask,gray);
|
||||||
|
|
||||||
Cloning obj;
|
Cloning obj;
|
||||||
obj.texture_flatten(src,cs_mask,gray,low_threshold,high_threshold,kernel_size,blend);
|
obj.textureFlatten(src,cs_mask,gray,low_threshold,high_threshold,kernel_size,blend);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,24 +53,24 @@ namespace cv
|
|||||||
class Cloning
|
class Cloning
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void normal_clone(const cv::Mat& destination, const cv::Mat &mask, const cv::Mat &wmask, cv::Mat &cloned, int flag);
|
void normalClone(const cv::Mat& destination, const cv::Mat &mask, const cv::Mat &wmask, cv::Mat &cloned, int flag);
|
||||||
void illum_change(cv::Mat &I, cv::Mat &mask, cv::Mat &wmask, cv::Mat &cloned, float alpha, float beta);
|
void illuminationChange(cv::Mat &I, cv::Mat &mask, cv::Mat &wmask, cv::Mat &cloned, float alpha, float beta);
|
||||||
void local_color_change(cv::Mat &I, cv::Mat &mask, cv::Mat &wmask, cv::Mat &cloned, float red_mul, float green_mul, float blue_mul);
|
void localColorChange(cv::Mat &I, cv::Mat &mask, cv::Mat &wmask, cv::Mat &cloned, float red_mul, float green_mul, float blue_mul);
|
||||||
void texture_flatten(cv::Mat &I, cv::Mat &mask, cv::Mat &wmask, float low_threshold, float high_threhold, int kernel_size, cv::Mat &cloned);
|
void textureFlatten(cv::Mat &I, cv::Mat &mask, cv::Mat &wmask, float low_threshold, float high_threhold, int kernel_size, cv::Mat &cloned);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void init_var(const cv::Mat &destination, const cv::Mat &binaryMask);
|
void initVariables(const cv::Mat &destination, const cv::Mat &binaryMask);
|
||||||
void compute_derivatives(const cv::Mat &destination, const cv::Mat &patch, const cv::Mat &binaryMask);
|
void computeDerivatives(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 scalarProduct(cv::Mat mat, float r, float g, float b);
|
||||||
void poisson(const cv::Mat &destination);
|
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(const Mat& src, Mat& dest, bool invert = false);
|
void dst(const Mat& src, Mat& dest, bool invert = false);
|
||||||
void idst(const Mat& src, Mat& dest);
|
void idst(const Mat& src, Mat& dest);
|
||||||
void solve(const cv::Mat &img, std::vector<float>& mod_diff, cv::Mat &result);
|
void solve(const cv::Mat &img, std::vector<float>& mod_diff, cv::Mat &result);
|
||||||
void poisson_solver(const cv::Mat &img, cv::Mat &gxx , cv::Mat &gyy, cv::Mat &result);
|
void poissonSolver(const cv::Mat &img, cv::Mat &gxx , cv::Mat &gyy, cv::Mat &result);
|
||||||
|
|
||||||
void array_product(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& result) const;
|
void arrayProduct(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& result) const;
|
||||||
|
|
||||||
void computeGradientX(const cv::Mat &img, cv::Mat &gx);
|
void computeGradientX(const cv::Mat &img, cv::Mat &gx);
|
||||||
void computeGradientY(const cv::Mat &img, cv::Mat &gy);
|
void computeGradientY(const cv::Mat &img, cv::Mat &gy);
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ void Cloning::solve(const Mat &img, std::vector<float>& mod_diff, Mat &result)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::poisson_solver(const Mat &img, Mat &laplacianX , Mat &laplacianY, Mat &result)
|
void Cloning::poissonSolver(const Mat &img, Mat &laplacianX , Mat &laplacianY, Mat &result)
|
||||||
{
|
{
|
||||||
|
|
||||||
const int w = img.size().width;
|
const int w = img.size().width;
|
||||||
@@ -237,7 +237,7 @@ void Cloning::poisson_solver(const Mat &img, Mat &laplacianX , Mat &laplacianY,
|
|||||||
solve(img,mod_diff,result);
|
solve(img,mod_diff,result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::init_var(const Mat &destination, const Mat &binaryMask)
|
void Cloning::initVariables(const Mat &destination, const Mat &binaryMask)
|
||||||
{
|
{
|
||||||
destinationGradientX = Mat(destination.size(),CV_32FC3);
|
destinationGradientX = Mat(destination.size(),CV_32FC3);
|
||||||
destinationGradientY = Mat(destination.size(),CV_32FC3);
|
destinationGradientY = Mat(destination.size(),CV_32FC3);
|
||||||
@@ -247,7 +247,7 @@ void Cloning::init_var(const Mat &destination, const Mat &binaryMask)
|
|||||||
binaryMaskFloat = Mat(binaryMask.size(),CV_32FC1);
|
binaryMaskFloat = Mat(binaryMask.size(),CV_32FC1);
|
||||||
binaryMaskFloatInverted = Mat(binaryMask.size(),CV_32FC1);
|
binaryMaskFloatInverted = Mat(binaryMask.size(),CV_32FC1);
|
||||||
|
|
||||||
//init of the filters used in the dft
|
//init of the filters used in the dst
|
||||||
const int w = destination.size().width;
|
const int w = destination.size().width;
|
||||||
filter_X.resize(w - 2);
|
filter_X.resize(w - 2);
|
||||||
for(int i = 0 ; i < w-2 ; ++i)
|
for(int i = 0 ; i < w-2 ; ++i)
|
||||||
@@ -259,9 +259,9 @@ void Cloning::init_var(const Mat &destination, const Mat &binaryMask)
|
|||||||
filter_Y[j] = 2.0f * std::cos(CV_PI * (j + 1) / (h - 1));
|
filter_Y[j] = 2.0f * std::cos(CV_PI * (j + 1) / (h - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::compute_derivatives(const Mat& destination, const Mat &patch, const Mat &binaryMask)
|
void Cloning::computeDerivatives(const Mat& destination, const Mat &patch, const Mat &binaryMask)
|
||||||
{
|
{
|
||||||
init_var(destination,binaryMask);
|
initVariables(destination,binaryMask);
|
||||||
|
|
||||||
computeGradientX(destination,destinationGradientX);
|
computeGradientX(destination,destinationGradientX);
|
||||||
computeGradientY(destination,destinationGradientY);
|
computeGradientY(destination,destinationGradientY);
|
||||||
@@ -276,7 +276,7 @@ void Cloning::compute_derivatives(const Mat& destination, const Mat &patch, cons
|
|||||||
binaryMask.convertTo(binaryMaskFloat,CV_32FC1,1.0/255.0);
|
binaryMask.convertTo(binaryMaskFloat,CV_32FC1,1.0/255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::scalar_product(Mat mat, float r, float g, float b)
|
void Cloning::scalarProduct(Mat mat, float r, float g, float b)
|
||||||
{
|
{
|
||||||
vector <Mat> channels;
|
vector <Mat> channels;
|
||||||
split(mat,channels);
|
split(mat,channels);
|
||||||
@@ -286,7 +286,7 @@ void Cloning::scalar_product(Mat mat, float r, float g, float b)
|
|||||||
merge(channels,mat);
|
merge(channels,mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::array_product(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& result) const
|
void Cloning::arrayProduct(const cv::Mat& lhs, const cv::Mat& rhs, cv::Mat& result) const
|
||||||
{
|
{
|
||||||
vector <Mat> lhs_channels;
|
vector <Mat> lhs_channels;
|
||||||
vector <Mat> result_channels;
|
vector <Mat> result_channels;
|
||||||
@@ -318,7 +318,7 @@ void Cloning::poisson(const Mat &destination)
|
|||||||
|
|
||||||
for(int chan = 0 ; chan < 3 ; ++chan)
|
for(int chan = 0 ; chan < 3 ; ++chan)
|
||||||
{
|
{
|
||||||
poisson_solver(output[chan], rgbx_channel[chan], rgby_channel[chan], output[chan]);
|
poissonSolver(output[chan], rgbx_channel[chan], rgby_channel[chan], output[chan]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,27 +328,27 @@ void Cloning::evaluate(const Mat &I, const Mat &wmask, const Mat &cloned)
|
|||||||
|
|
||||||
wmask.convertTo(binaryMaskFloatInverted,CV_32FC1,1.0/255.0);
|
wmask.convertTo(binaryMaskFloatInverted,CV_32FC1,1.0/255.0);
|
||||||
|
|
||||||
array_product(destinationGradientX,binaryMaskFloatInverted, destinationGradientX);
|
arrayProduct(destinationGradientX,binaryMaskFloatInverted, destinationGradientX);
|
||||||
array_product(destinationGradientY,binaryMaskFloatInverted, destinationGradientY);
|
arrayProduct(destinationGradientY,binaryMaskFloatInverted, destinationGradientY);
|
||||||
|
|
||||||
poisson(I);
|
poisson(I);
|
||||||
|
|
||||||
merge(output,cloned);
|
merge(output,cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::normal_clone(const Mat &destination, const Mat &patch, const Mat &binaryMask, Mat &cloned, int flag)
|
void Cloning::normalClone(const Mat &destination, const Mat &patch, const Mat &binaryMask, Mat &cloned, int flag)
|
||||||
{
|
{
|
||||||
int w = destination.size().width;
|
int w = destination.size().width;
|
||||||
int h = destination.size().height;
|
int h = destination.size().height;
|
||||||
int channel = destination.channels();
|
int channel = destination.channels();
|
||||||
|
|
||||||
compute_derivatives(destination,patch,binaryMask);
|
computeDerivatives(destination,patch,binaryMask);
|
||||||
|
|
||||||
switch(flag)
|
switch(flag)
|
||||||
{
|
{
|
||||||
case NORMAL_CLONE:
|
case NORMAL_CLONE:
|
||||||
array_product(patchGradientX,binaryMaskFloat, patchGradientX);
|
arrayProduct(patchGradientX,binaryMaskFloat, patchGradientX);
|
||||||
array_product(patchGradientY,binaryMaskFloat, patchGradientY);
|
arrayProduct(patchGradientY,binaryMaskFloat, patchGradientY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MIXED_CLONE:
|
case MIXED_CLONE:
|
||||||
@@ -395,8 +395,8 @@ void Cloning::normal_clone(const Mat &destination, const Mat &patch, const Mat &
|
|||||||
computeGradientX(gray8,patchGradientX);
|
computeGradientX(gray8,patchGradientX);
|
||||||
computeGradientY(gray8,patchGradientY);
|
computeGradientY(gray8,patchGradientY);
|
||||||
|
|
||||||
array_product(patchGradientX, binaryMaskFloat, patchGradientX);
|
arrayProduct(patchGradientX, binaryMaskFloat, patchGradientX);
|
||||||
array_product(patchGradientY, binaryMaskFloat, patchGradientY);
|
arrayProduct(patchGradientY, binaryMaskFloat, patchGradientY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -404,25 +404,25 @@ void Cloning::normal_clone(const Mat &destination, const Mat &patch, const Mat &
|
|||||||
evaluate(destination,binaryMask,cloned);
|
evaluate(destination,binaryMask,cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::local_color_change(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, float red_mul=1.0,
|
void Cloning::localColorChange(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, float red_mul=1.0,
|
||||||
float green_mul=1.0, float blue_mul=1.0)
|
float green_mul=1.0, float blue_mul=1.0)
|
||||||
{
|
{
|
||||||
compute_derivatives(I,mask,wmask);
|
computeDerivatives(I,mask,wmask);
|
||||||
|
|
||||||
array_product(patchGradientX,binaryMaskFloat, patchGradientX);
|
arrayProduct(patchGradientX,binaryMaskFloat, patchGradientX);
|
||||||
array_product(patchGradientY,binaryMaskFloat, patchGradientY);
|
arrayProduct(patchGradientY,binaryMaskFloat, patchGradientY);
|
||||||
scalar_product(patchGradientX,red_mul,green_mul,blue_mul);
|
scalarProduct(patchGradientX,red_mul,green_mul,blue_mul);
|
||||||
scalar_product(patchGradientY,red_mul,green_mul,blue_mul);
|
scalarProduct(patchGradientY,red_mul,green_mul,blue_mul);
|
||||||
|
|
||||||
evaluate(I,wmask,cloned);
|
evaluate(I,wmask,cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::illum_change(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, float alpha, float beta)
|
void Cloning::illuminationChange(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, float alpha, float beta)
|
||||||
{
|
{
|
||||||
compute_derivatives(I,mask,wmask);
|
computeDerivatives(I,mask,wmask);
|
||||||
|
|
||||||
array_product(patchGradientX,binaryMaskFloat, patchGradientX);
|
arrayProduct(patchGradientX,binaryMaskFloat, patchGradientX);
|
||||||
array_product(patchGradientY,binaryMaskFloat, patchGradientY);
|
arrayProduct(patchGradientY,binaryMaskFloat, patchGradientY);
|
||||||
|
|
||||||
Mat mag = Mat(I.size(),CV_32FC3);
|
Mat mag = Mat(I.size(),CV_32FC3);
|
||||||
magnitude(patchGradientX,patchGradientY,mag);
|
magnitude(patchGradientX,patchGradientY,mag);
|
||||||
@@ -447,10 +447,10 @@ void Cloning::illum_change(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, float alp
|
|||||||
evaluate(I,wmask,cloned);
|
evaluate(I,wmask,cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloning::texture_flatten(Mat &I, Mat &mask, Mat &wmask, float low_threshold,
|
void Cloning::textureFlatten(Mat &I, Mat &mask, Mat &wmask, float low_threshold,
|
||||||
float high_threshold, int kernel_size, Mat &cloned)
|
float high_threshold, int kernel_size, Mat &cloned)
|
||||||
{
|
{
|
||||||
compute_derivatives(I,mask,wmask);
|
computeDerivatives(I,mask,wmask);
|
||||||
|
|
||||||
Mat out = Mat(mask.size(),CV_8UC1);
|
Mat out = Mat(mask.size(),CV_8UC1);
|
||||||
Canny(mask,out,low_threshold,high_threshold,kernel_size);
|
Canny(mask,out,low_threshold,high_threshold,kernel_size);
|
||||||
@@ -461,8 +461,8 @@ void Cloning::texture_flatten(Mat &I, Mat &mask, Mat &wmask, float low_threshold
|
|||||||
zeros.copyTo(patchGradientX, zerosMask);
|
zeros.copyTo(patchGradientX, zerosMask);
|
||||||
zeros.copyTo(patchGradientY, zerosMask);
|
zeros.copyTo(patchGradientY, zerosMask);
|
||||||
|
|
||||||
array_product(patchGradientX,binaryMaskFloat, patchGradientX);
|
arrayProduct(patchGradientX,binaryMaskFloat, patchGradientX);
|
||||||
array_product(patchGradientY,binaryMaskFloat, patchGradientY);
|
arrayProduct(patchGradientY,binaryMaskFloat, patchGradientY);
|
||||||
|
|
||||||
evaluate(I,wmask,cloned);
|
evaluate(I,wmask,cloned);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user