|
|
@ -46,23 +46,23 @@ Using Canny's criteria to derive a recursively implemented optimal edge detector |
|
|
|
namespace cv { |
|
|
|
namespace cv { |
|
|
|
namespace ximgproc { |
|
|
|
namespace ximgproc { |
|
|
|
template<typename T> static void |
|
|
|
template<typename T> static void |
|
|
|
VerticalIIRFilter(Mat &img,Mat &dst,const Range &r,double alphaDerive) |
|
|
|
VerticalIIRFilter(Mat &img,Mat &dst,const Range &r,double alpha,double omega) |
|
|
|
{ |
|
|
|
{ |
|
|
|
float *f2; |
|
|
|
float *f2; |
|
|
|
int tailleSequence = (img.rows>img.cols) ? img.rows : img.cols; |
|
|
|
int tailleSequence = (img.rows>img.cols) ? img.rows : img.cols; |
|
|
|
Mat matG1(1, tailleSequence, CV_64FC1), matG2(1, tailleSequence, CV_64FC1); |
|
|
|
Mat matG1(1, tailleSequence, CV_64FC1), matG2(1, tailleSequence, CV_64FC1); |
|
|
|
double *g1 = matG1.ptr<double>(0), *g2 = (double*)matG2.ptr<double>(0); |
|
|
|
double *g1 = matG1.ptr<double>(0), *g2 = (double*)matG2.ptr<double>(0); |
|
|
|
double kp = pow(1 - exp(-alphaDerive), 2.0) / exp(-alphaDerive); |
|
|
|
double a2, a3; |
|
|
|
double a1, a2, a3, a4; |
|
|
|
|
|
|
|
double b1, b2; |
|
|
|
double b1, b2; |
|
|
|
int rows = img.rows, cols = img.cols; |
|
|
|
int rows = img.rows, cols = img.cols; |
|
|
|
|
|
|
|
double c = (1 - 2 * exp(-alpha)*cos(omega) + exp(-2 * alpha)) / (exp(-alpha)*sin(omega)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double a = -c * exp(-alpha)*sin(omega); |
|
|
|
|
|
|
|
a2 = 1;// kp*exp(-alpha);
|
|
|
|
|
|
|
|
a3 = 1;//-kp*exp(-alpha);
|
|
|
|
|
|
|
|
b1 = -2 * exp(-alpha)*cos(omega); |
|
|
|
|
|
|
|
b2 = exp(-2 * alpha); |
|
|
|
|
|
|
|
|
|
|
|
kp = pow(1 - exp(-alphaDerive), 2.0) / exp(-alphaDerive); |
|
|
|
|
|
|
|
a1 = 0; |
|
|
|
|
|
|
|
a2 = kp*exp(-alphaDerive), a3 = -kp*exp(-alphaDerive); |
|
|
|
|
|
|
|
a4 = 0; |
|
|
|
|
|
|
|
b1 = 2 * exp(-alphaDerive); |
|
|
|
|
|
|
|
b2 = -exp(-2 * alphaDerive); |
|
|
|
|
|
|
|
for (int j = r.start; j<r.end; j++) |
|
|
|
for (int j = r.start; j<r.end; j++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Causal vertical IIR filter
|
|
|
|
// Causal vertical IIR filter
|
|
|
@ -71,78 +71,76 @@ VerticalIIRFilter(Mat &img,Mat &dst,const Range &r,double alphaDerive) |
|
|
|
f2 += j; |
|
|
|
f2 += j; |
|
|
|
c1 += j; |
|
|
|
c1 += j; |
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
g1[i] = (a1 + a2)* *c1; |
|
|
|
g1[i] = a2* *c1; |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
c1 += cols; |
|
|
|
c1 += cols; |
|
|
|
g1[i] = a1 * *c1 + a2 * c1[-cols] + (b1)* g1[i - 1]; |
|
|
|
g1[i] =a2 * c1[-cols] - (b1)* g1[i - 1]; |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
c1 += cols; |
|
|
|
c1 += cols; |
|
|
|
for (i = 2; i<rows; i++, c1 += cols) |
|
|
|
for (i = 2; i<rows; i++, c1 += cols) |
|
|
|
g1[i] = a1 * *c1 + a2 * c1[-cols] + b1*g1[i - 1] + b2 *g1[i - 2]; |
|
|
|
g1[i] = a2 * c1[-cols] - b1*g1[i - 1] - b2 *g1[i - 2]; |
|
|
|
// Anticausal vertical IIR filter
|
|
|
|
// Anticausal vertical IIR filter
|
|
|
|
c1 = img.ptr<T>(0); |
|
|
|
c1 = img.ptr<T>(0); |
|
|
|
c1 += (rows - 1)*cols + j; |
|
|
|
c1 += (rows - 1)*cols + j; |
|
|
|
i = rows - 1; |
|
|
|
i = rows - 1; |
|
|
|
g2[i] = (a3 + a4)* *c1; |
|
|
|
g2[i] = a3 * *c1; |
|
|
|
i--; |
|
|
|
i--; |
|
|
|
c1 -= cols; |
|
|
|
c1 -= cols; |
|
|
|
g2[i] = a3* c1[cols] + a4 * c1[cols] + (b1)*g2[i + 1]; |
|
|
|
g2[i] = a3* c1[cols] + (b1)*g2[i + 1]; |
|
|
|
i--; |
|
|
|
i--; |
|
|
|
c1 -= cols; |
|
|
|
c1 -= cols; |
|
|
|
for (i = rows - 3; i >= 0; i--, c1 -= cols) |
|
|
|
for (i = rows - 3; i >= 0; i--, c1 -= cols) |
|
|
|
g2[i] = a3*c1[cols] + a4* c1[2 * cols] + |
|
|
|
g2[i] = a3*c1[cols] - |
|
|
|
b1*g2[i + 1] + b2*g2[i + 2]; |
|
|
|
b1*g2[i + 1] - b2*g2[i + 2]; |
|
|
|
for (i = 0; i<rows; i++, f2 += cols) |
|
|
|
for (i = 0; i<rows; i++, f2 += cols) |
|
|
|
*f2 = (float)(g1[i] + g2[i]); |
|
|
|
*f2 = static_cast<float>(a*(g1[i] - g2[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<typename T> static void |
|
|
|
template<typename T> static void |
|
|
|
HorizontalIIRFilter(Mat &img, Mat &dst, const Range &r, double alphaDerive) |
|
|
|
HorizontalIIRFilter(Mat &img, Mat &dst, const Range &r, double alpha, double omega) |
|
|
|
{ |
|
|
|
{ |
|
|
|
float *f1; |
|
|
|
float *f1; |
|
|
|
int rows = img.rows, cols = img.cols; |
|
|
|
int rows = img.rows, cols = img.cols; |
|
|
|
int tailleSequence = (rows>cols) ? rows : cols; |
|
|
|
int tailleSequence = (rows>cols) ? rows : cols; |
|
|
|
Mat matG1(1, tailleSequence, CV_64FC1), matG2(1, tailleSequence, CV_64FC1); |
|
|
|
Mat matG1(1, tailleSequence, CV_64FC1), matG2(1, tailleSequence, CV_64FC1); |
|
|
|
double *g1 = (double*)matG1.ptr(0), *g2 = (double*)matG2.ptr(0); |
|
|
|
double *g1 = (double*)matG1.ptr(0), *g2 = (double*)matG2.ptr(0); |
|
|
|
double kp;; |
|
|
|
double a,a2, a3; |
|
|
|
double a1, a2, a3, a4; |
|
|
|
|
|
|
|
double b1, b2; |
|
|
|
double b1, b2; |
|
|
|
|
|
|
|
double c = (1 - 2 * exp(-alpha)*cos(omega) + exp(-2 * alpha)) / (exp(-alpha)*sin(omega)); |
|
|
|
|
|
|
|
|
|
|
|
kp = pow(1 - exp(-alphaDerive), 2.0) / exp(-alphaDerive); |
|
|
|
a = -c*exp(-alpha)*sin(omega); |
|
|
|
a1 = 0; |
|
|
|
a2 = 1;// kp*exp(-alpha);
|
|
|
|
a2 = kp*exp(-alphaDerive); |
|
|
|
a3 = 1;//-kp*exp(-alpha);
|
|
|
|
a3 = -kp*exp(-alphaDerive); |
|
|
|
b1 = -2 * exp(-alpha)*cos(omega); |
|
|
|
a4 = 0; |
|
|
|
b2 = exp(-2 * alpha); |
|
|
|
b1 = 2 * exp(-alphaDerive); |
|
|
|
|
|
|
|
b2 = -exp(-2 * alphaDerive); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = r.start; i<r.end; i++) |
|
|
|
for (int i = r.start; i<r.end; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
f1 = dst.ptr<float>(i); |
|
|
|
f1 = dst.ptr<float>(i); |
|
|
|
T *c1 = img.ptr<T>(i); |
|
|
|
T *c1 = img.ptr<T>(i); |
|
|
|
int j = 0; |
|
|
|
int j = 0; |
|
|
|
g1[j] = (a1 + a2)* *c1; |
|
|
|
g1[j] = a2* *c1; |
|
|
|
j++; |
|
|
|
j++; |
|
|
|
c1++; |
|
|
|
c1++; |
|
|
|
g1[j] = a1 * c1[0] + a2*c1[j - 1] + (b1)* g1[j - 1]; |
|
|
|
g1[j] = a2*c1[j - 1] - (b1)* g1[j - 1]; |
|
|
|
j++; |
|
|
|
j++; |
|
|
|
c1++; |
|
|
|
c1++; |
|
|
|
for (j = 2; j<cols; j++, c1++) |
|
|
|
for (j = 2; j<cols; j++, c1++) |
|
|
|
g1[j] = a1 * c1[0] + a2 * c1[-1] + b1*g1[j - 1] + b2*g1[j - 2]; |
|
|
|
g1[j] = a2 * c1[-1] - b1*g1[j - 1] - b2*g1[j - 2]; |
|
|
|
c1 = img.ptr<T>(0); |
|
|
|
c1 = img.ptr<T>(0); |
|
|
|
c1 += i*cols + cols - 1; |
|
|
|
c1 += i*cols + cols - 1; |
|
|
|
j = cols - 1; |
|
|
|
j = cols - 1; |
|
|
|
g2[j] = (a3 + a4)* *c1; |
|
|
|
g2[j] = a3* *c1; |
|
|
|
j--; |
|
|
|
j--; |
|
|
|
c1--; |
|
|
|
c1--; |
|
|
|
g2[j] = (a3 + a4) * c1[1] + b1 * g2[j + 1]; |
|
|
|
g2[j] = a3 * c1[1] - b1 * g2[j + 1]; |
|
|
|
j--; |
|
|
|
j--; |
|
|
|
c1--; |
|
|
|
c1--; |
|
|
|
for (j = cols - 3; j >= 0; j--, c1--) |
|
|
|
for (j = cols - 3; j >= 0; j--, c1--) |
|
|
|
g2[j] = a3*c1[1] + a4*c1[2] + b1*g2[j + 1] + b2*g2[j + 2]; |
|
|
|
g2[j] = a3*c1[1] - b1*g2[j + 1] - b2*g2[j + 2]; |
|
|
|
for (j = 0; j<cols; j++, f1++) |
|
|
|
for (j = 0; j<cols; j++, f1++) |
|
|
|
*f1 = (float)(g1[j] + g2[j]); |
|
|
|
*f1 = static_cast<float>(a*(g1[j] - g2[j])); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -151,15 +149,17 @@ class ParallelGradientDericheYCols : public ParallelLoopBody |
|
|
|
private: |
|
|
|
private: |
|
|
|
Mat &img; |
|
|
|
Mat &img; |
|
|
|
Mat &dst; |
|
|
|
Mat &dst; |
|
|
|
double alphaDerive; |
|
|
|
double alpha; |
|
|
|
|
|
|
|
double omega; |
|
|
|
bool verbose; |
|
|
|
bool verbose; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
ParallelGradientDericheYCols(Mat &imgSrc, Mat &d, double ald) : |
|
|
|
ParallelGradientDericheYCols(Mat &imgSrc, Mat &d, double ald,double o) : |
|
|
|
img(imgSrc), |
|
|
|
img(imgSrc), |
|
|
|
dst(d), |
|
|
|
dst(d), |
|
|
|
alphaDerive(ald), |
|
|
|
alpha(ald), |
|
|
|
|
|
|
|
omega(o), |
|
|
|
verbose(false) |
|
|
|
verbose(false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int type = img.depth(); |
|
|
|
int type = img.depth(); |
|
|
@ -175,19 +175,19 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
switch (img.depth()) { |
|
|
|
switch (img.depth()) { |
|
|
|
case CV_8U: |
|
|
|
case CV_8U: |
|
|
|
VerticalIIRFilter<uchar>(img,dst,range, alphaDerive); |
|
|
|
VerticalIIRFilter<uchar>(img,dst,range, alpha,omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_8S: |
|
|
|
case CV_8S: |
|
|
|
VerticalIIRFilter<char>(img, dst, range, alphaDerive); |
|
|
|
VerticalIIRFilter<char>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_16U: |
|
|
|
case CV_16U: |
|
|
|
VerticalIIRFilter<ushort>(img, dst, range, alphaDerive); |
|
|
|
VerticalIIRFilter<ushort>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_16S: |
|
|
|
case CV_16S: |
|
|
|
VerticalIIRFilter<short>(img, dst, range, alphaDerive); |
|
|
|
VerticalIIRFilter<short>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_32F: |
|
|
|
case CV_32F: |
|
|
|
VerticalIIRFilter<float>(img, dst, range, alphaDerive); |
|
|
|
VerticalIIRFilter<float>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
return; |
|
|
|
return; |
|
|
@ -204,14 +204,16 @@ class ParallelGradientDericheYRows : public ParallelLoopBody |
|
|
|
private: |
|
|
|
private: |
|
|
|
Mat &img; |
|
|
|
Mat &img; |
|
|
|
Mat &dst; |
|
|
|
Mat &dst; |
|
|
|
double alphaMoyenne; |
|
|
|
double alpha; |
|
|
|
|
|
|
|
double omega; |
|
|
|
bool verbose; |
|
|
|
bool verbose; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
ParallelGradientDericheYRows(Mat& imgSrc, Mat &d, double alm) : |
|
|
|
ParallelGradientDericheYRows(Mat& imgSrc, Mat &d, double ald,double o) : |
|
|
|
img(imgSrc), |
|
|
|
img(imgSrc), |
|
|
|
dst(d), |
|
|
|
dst(d), |
|
|
|
alphaMoyenne(alm), |
|
|
|
alpha(ald), |
|
|
|
|
|
|
|
omega(o), |
|
|
|
verbose(false) |
|
|
|
verbose(false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int type = img.depth(); |
|
|
|
int type = img.depth(); |
|
|
@ -228,42 +230,44 @@ public: |
|
|
|
int tailleSequence = (img.rows>img.cols) ? img.rows : img.cols; |
|
|
|
int tailleSequence = (img.rows>img.cols) ? img.rows : img.cols; |
|
|
|
Mat matG1(1,tailleSequence,CV_64FC1), matG2(1,tailleSequence,CV_64FC1); |
|
|
|
Mat matG1(1,tailleSequence,CV_64FC1), matG2(1,tailleSequence,CV_64FC1); |
|
|
|
double *g1 = matG1.ptr<double>(0), *g2 = matG2.ptr<double>(0); |
|
|
|
double *g1 = matG1.ptr<double>(0), *g2 = matG2.ptr<double>(0); |
|
|
|
double k, a5, a6, a7, a8; |
|
|
|
|
|
|
|
double b3, b4; |
|
|
|
|
|
|
|
int cols = img.cols; |
|
|
|
int cols = img.cols; |
|
|
|
|
|
|
|
|
|
|
|
k = pow(1 - exp(-alphaMoyenne), 2.0) / (1 + 2 * alphaMoyenne*exp(-alphaMoyenne) - exp(-2 * alphaMoyenne)); |
|
|
|
|
|
|
|
a5 = k; |
|
|
|
double a2po2 = (alpha*alpha + omega * omega); |
|
|
|
a6 = k*exp(-alphaMoyenne)*(alphaMoyenne - 1); |
|
|
|
double k = (1 - 2 * exp(-alpha)*cos(omega) + exp(-2 * alpha))*a2po2; |
|
|
|
a7 = k*exp(-alphaMoyenne)*(alphaMoyenne + 1); |
|
|
|
k = k / (2 * alpha*exp(-alpha)*sin(omega) + omega - omega * exp(-2 * alpha)); |
|
|
|
a8 = -k*exp(-2 * alphaMoyenne); |
|
|
|
double c1 = k * alpha / a2po2; |
|
|
|
b3 = 2 * exp(-alphaMoyenne); |
|
|
|
double c2 = k * omega / a2po2; |
|
|
|
b4 = -exp(-2 * alphaMoyenne); |
|
|
|
double a0 = c2; |
|
|
|
|
|
|
|
double a1 = (-c2 * cos(omega) + c1 * sin(omega))*exp(-alpha); |
|
|
|
|
|
|
|
double b1 = -2 * exp(-alpha)*cos(omega); |
|
|
|
|
|
|
|
double b2 = exp(-2 * alpha); |
|
|
|
|
|
|
|
double a2 = a1 - c2 * b1, a3 = -c2 * b2; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = range.start; i<range.end; i++) |
|
|
|
for (int i = range.start; i<range.end; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
f2 = dst.ptr<float>(i); |
|
|
|
f2 = dst.ptr<float>(i); |
|
|
|
f1 = img.ptr<float>(i); |
|
|
|
f1 = img.ptr<float>(i); |
|
|
|
int j = 0; |
|
|
|
int j = 0; |
|
|
|
g1[j] = (a5 + a6)* *f1; |
|
|
|
g1[j] = (a0 + a1)* *f1; |
|
|
|
j++; |
|
|
|
j++; |
|
|
|
f1++; |
|
|
|
f1++; |
|
|
|
g1[j] = a5 * f1[0] + a6*f1[j - 1] + (b3)* g1[j - 1]; |
|
|
|
g1[j] = a0 * f1[0] + a1*f1[j - 1] - b1* g1[j - 1]; |
|
|
|
j++; |
|
|
|
j++; |
|
|
|
f1++; |
|
|
|
f1++; |
|
|
|
for (j = 2; j<cols; j++, f1++) |
|
|
|
for (j = 2; j<cols; j++, f1++) |
|
|
|
g1[j] = a5 * f1[0] + a6 * f1[-1] + b3*g1[j - 1] + b4*g1[j - 2]; |
|
|
|
g1[j] = a0 * f1[0] + a1 * f1[-1] - b1*g1[j - 1] - b2*g1[j - 2]; |
|
|
|
f1 = ((float*)img.ptr(0)); |
|
|
|
f1 = ((float*)img.ptr(0)); |
|
|
|
f1 += i*cols + cols - 1; |
|
|
|
f1 += i*cols + cols - 1; |
|
|
|
j = cols - 1; |
|
|
|
j = cols - 1; |
|
|
|
g2[j] = (a7 + a8)* *f1; |
|
|
|
g2[j] = (a2 + a3)* *f1; |
|
|
|
j--; |
|
|
|
j--; |
|
|
|
f1--; |
|
|
|
f1--; |
|
|
|
g2[j] = (a7 + a8) * f1[1] + (b3)* g2[j + 1]; |
|
|
|
g2[j] = (a2 + a3) * f1[1] - b2* g2[j + 1]; |
|
|
|
j--; |
|
|
|
j--; |
|
|
|
f1--; |
|
|
|
f1--; |
|
|
|
for (j = cols - 3; j >= 0; j--, f1--) |
|
|
|
for (j = cols - 3; j >= 0; j--, f1--) |
|
|
|
g2[j] = a7*f1[1] + a8*f1[2] + b3*g2[j + 1] + b4*g2[j + 2]; |
|
|
|
g2[j] = a2*f1[1] + a3*f1[2] - b1*g2[j + 1] - b2*g2[j + 2]; |
|
|
|
for (j = 0; j<cols; j++, f2++) |
|
|
|
for (j = 0; j<cols; j++, f2++) |
|
|
|
*f2 = (float)(g1[j] + g2[j]); |
|
|
|
*f2 = (float)(g1[j] + g2[j]); |
|
|
|
} |
|
|
|
} |
|
|
@ -280,14 +284,16 @@ class ParallelGradientDericheXCols : public ParallelLoopBody |
|
|
|
private: |
|
|
|
private: |
|
|
|
Mat &img; |
|
|
|
Mat &img; |
|
|
|
Mat &dst; |
|
|
|
Mat &dst; |
|
|
|
double alphaMoyenne; |
|
|
|
double alpha; |
|
|
|
|
|
|
|
double omega; |
|
|
|
bool verbose; |
|
|
|
bool verbose; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
ParallelGradientDericheXCols(Mat& imgSrc, Mat &d, double alm) : |
|
|
|
ParallelGradientDericheXCols(Mat& imgSrc, Mat &d, double alm,double o) : |
|
|
|
img(imgSrc), |
|
|
|
img(imgSrc), |
|
|
|
dst(d), |
|
|
|
dst(d), |
|
|
|
alphaMoyenne(alm), |
|
|
|
alpha(alm), |
|
|
|
|
|
|
|
omega(o), |
|
|
|
verbose(false) |
|
|
|
verbose(false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int type = img.depth(); |
|
|
|
int type = img.depth(); |
|
|
@ -306,40 +312,43 @@ public: |
|
|
|
int tailleSequence = (rows>cols) ? rows : cols; |
|
|
|
int tailleSequence = (rows>cols) ? rows : cols; |
|
|
|
Mat matG1(1,tailleSequence,CV_64FC1), matG2(1,tailleSequence,CV_64FC1); |
|
|
|
Mat matG1(1,tailleSequence,CV_64FC1), matG2(1,tailleSequence,CV_64FC1); |
|
|
|
double *g1 = (double*)matG1.ptr(0), *g2 = (double*)matG2.ptr(0); |
|
|
|
double *g1 = (double*)matG1.ptr(0), *g2 = (double*)matG2.ptr(0); |
|
|
|
double k, a5, a6, a7, a8 = 0; |
|
|
|
double a2po2 = (alpha*alpha + omega * omega); |
|
|
|
double b3, b4; |
|
|
|
double k = (1 - 2 * exp(-alpha)*cos(omega) + exp(-2 * alpha))*a2po2; |
|
|
|
|
|
|
|
k = k / (2 * alpha*exp(-alpha)*sin(omega) + omega - omega * exp(-2 * alpha)); |
|
|
|
|
|
|
|
double c1 = k * alpha / a2po2; |
|
|
|
|
|
|
|
double c2 = k * omega / a2po2; |
|
|
|
|
|
|
|
double a0 = c2; |
|
|
|
|
|
|
|
double a1 = (-c2 * cos(omega) + c1 * sin(omega))*exp(-alpha); |
|
|
|
|
|
|
|
double b1 = -2 * exp(-alpha)*cos(omega); |
|
|
|
|
|
|
|
double b2=exp(-2*alpha); |
|
|
|
|
|
|
|
double a2=a1-c2*b1, a3=-c2*b2; |
|
|
|
|
|
|
|
|
|
|
|
k = pow(1 - exp(-alphaMoyenne), 2.0) / (1 + 2 * alphaMoyenne*exp(-alphaMoyenne) - exp(-2 * alphaMoyenne)); |
|
|
|
|
|
|
|
a5 = k, a6 = k*exp(-alphaMoyenne)*(alphaMoyenne - 1); |
|
|
|
|
|
|
|
a7 = k*exp(-alphaMoyenne)*(alphaMoyenne + 1), a8 = -k*exp(-2 * alphaMoyenne); |
|
|
|
|
|
|
|
b3 = 2 * exp(-alphaMoyenne); |
|
|
|
|
|
|
|
b4 = -exp(-2 * alphaMoyenne); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = range.start; j<range.end; j++) |
|
|
|
for (int j = range.start; j<range.end; j++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
f1 = img.ptr<float>(0); |
|
|
|
f1 = img.ptr<float>(0); |
|
|
|
f1 += j; |
|
|
|
f1 += j; |
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
g1[i] = (a5 + a6)* *f1; |
|
|
|
g1[i] = (a0 + a1)* *f1; |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
f1 += cols; |
|
|
|
f1 += cols; |
|
|
|
g1[i] = a5 * *f1 + a6 * f1[-cols] + (b3)* g1[i - 1]; |
|
|
|
g1[i] = a0 * *f1 + a1 * f1[-cols] - (b1)* g1[i - 1]; |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
f1 += cols; |
|
|
|
f1 += cols; |
|
|
|
for (i = 2; i<rows; i++, f1 += cols) |
|
|
|
for (i = 2; i<rows; i++, f1 += cols) |
|
|
|
g1[i] = a5 * *f1 + a6 * f1[-cols] + b3*g1[i - 1] + b4 *g1[i - 2]; |
|
|
|
g1[i] = a0 * *f1 + a1 * f1[-cols] - b1*g1[i - 1] - b2 *g1[i - 2]; |
|
|
|
f1 = img.ptr<float>(0); |
|
|
|
f1 = img.ptr<float>(0); |
|
|
|
f1 += (rows - 1)*cols + j; |
|
|
|
f1 += (rows - 1)*cols + j; |
|
|
|
i = rows - 1; |
|
|
|
i = rows - 1; |
|
|
|
g2[i] = (a7 + a8)* *f1; |
|
|
|
g2[i] = (a2 + a3)* *f1; |
|
|
|
i--; |
|
|
|
i--; |
|
|
|
f1 -= cols; |
|
|
|
f1 -= cols; |
|
|
|
g2[i] = (a7 + a8)* f1[cols] + (b3)*g2[i + 1]; |
|
|
|
g2[i] = (a2 + a3)* f1[cols] - b2*g2[i + 1]; |
|
|
|
i--; |
|
|
|
i--; |
|
|
|
f1 -= cols; |
|
|
|
f1 -= cols; |
|
|
|
for (i = rows - 3; i >= 0; i--, f1 -= cols) |
|
|
|
for (i = rows - 3; i >= 0; i--, f1 -= cols) |
|
|
|
g2[i] = a7*f1[cols] + a8* f1[2 * cols] + |
|
|
|
g2[i] = a2*f1[cols] + a3* f1[2 * cols] - |
|
|
|
b3*g2[i + 1] + b4*g2[i + 2]; |
|
|
|
b1*g2[i + 1] - b2*g2[i + 2]; |
|
|
|
for (i = 0; i<rows; i++, f2 += cols) |
|
|
|
for (i = 0; i<rows; i++, f2 += cols) |
|
|
|
{ |
|
|
|
{ |
|
|
|
f2 = (dst.ptr<float>(i)) + (j*img.channels()); |
|
|
|
f2 = (dst.ptr<float>(i)) + (j*img.channels()); |
|
|
@ -358,14 +367,16 @@ class ParallelGradientDericheXRows : public ParallelLoopBody |
|
|
|
private: |
|
|
|
private: |
|
|
|
Mat &img; |
|
|
|
Mat &img; |
|
|
|
Mat &dst; |
|
|
|
Mat &dst; |
|
|
|
double alphaDerive; |
|
|
|
double alpha; |
|
|
|
|
|
|
|
double omega; |
|
|
|
bool verbose; |
|
|
|
bool verbose; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
ParallelGradientDericheXRows(Mat& imgSrc, Mat &d, double ald) : |
|
|
|
ParallelGradientDericheXRows(Mat& imgSrc, Mat &d, double ald, double o) : |
|
|
|
img(imgSrc), |
|
|
|
img(imgSrc), |
|
|
|
dst(d), |
|
|
|
dst(d), |
|
|
|
alphaDerive(ald), |
|
|
|
alpha(ald), |
|
|
|
|
|
|
|
omega(o), |
|
|
|
verbose(false) |
|
|
|
verbose(false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int type = img.depth(); |
|
|
|
int type = img.depth(); |
|
|
@ -381,19 +392,19 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
switch (img.depth()) { |
|
|
|
switch (img.depth()) { |
|
|
|
case CV_8U: |
|
|
|
case CV_8U: |
|
|
|
HorizontalIIRFilter<uchar>(img,dst,range,alphaDerive); |
|
|
|
HorizontalIIRFilter<uchar>(img,dst,range, alpha,omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_8S: |
|
|
|
case CV_8S: |
|
|
|
HorizontalIIRFilter<char>(img, dst, range, alphaDerive); |
|
|
|
HorizontalIIRFilter<char>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_16U: |
|
|
|
case CV_16U: |
|
|
|
HorizontalIIRFilter<ushort>(img, dst, range, alphaDerive); |
|
|
|
HorizontalIIRFilter<ushort>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_16S: |
|
|
|
case CV_16S: |
|
|
|
HorizontalIIRFilter<short>(img, dst, range, alphaDerive); |
|
|
|
HorizontalIIRFilter<short>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CV_32F: |
|
|
|
case CV_32F: |
|
|
|
HorizontalIIRFilter<float>(img, dst, range, alphaDerive); |
|
|
|
HorizontalIIRFilter<float>(img, dst, range, alpha, omega); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
return; |
|
|
|
return; |
|
|
@ -404,10 +415,11 @@ public: |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void GradientDericheY(InputArray _op, OutputArray _dst,double alphaDerive, double alphaMean) |
|
|
|
void GradientDericheY(InputArray _op, OutputArray _dst,double alphaDerive, double omega) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<Mat> planSrc; |
|
|
|
std::vector<Mat> planSrc; |
|
|
|
split(_op, planSrc); |
|
|
|
split(_op, planSrc); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Mat> planTmp; |
|
|
|
std::vector<Mat> planTmp; |
|
|
|
std::vector<Mat> planDst; |
|
|
|
std::vector<Mat> planDst; |
|
|
|
for (size_t i = 0; i < planSrc.size(); i++) |
|
|
|
for (size_t i = 0; i < planSrc.size(); i++) |
|
|
@ -415,15 +427,15 @@ void GradientDericheY(InputArray _op, OutputArray _dst,double alphaDerive, doubl |
|
|
|
planTmp.push_back(Mat(_op.size(), CV_32FC1)); |
|
|
|
planTmp.push_back(Mat(_op.size(), CV_32FC1)); |
|
|
|
planDst.push_back(Mat(_op.size(), CV_32FC1)); |
|
|
|
planDst.push_back(Mat(_op.size(), CV_32FC1)); |
|
|
|
CV_Assert(planSrc[i].isContinuous() && planTmp[i].isContinuous() && planDst[i].isContinuous()); |
|
|
|
CV_Assert(planSrc[i].isContinuous() && planTmp[i].isContinuous() && planDst[i].isContinuous()); |
|
|
|
ParallelGradientDericheYCols x(planSrc[i], planTmp[i], alphaDerive); |
|
|
|
ParallelGradientDericheYCols x(planSrc[i], planTmp[i], alphaDerive,omega); |
|
|
|
parallel_for_(Range(0, planSrc[i].cols), x, getNumThreads()); |
|
|
|
parallel_for_(Range(0, planSrc[i].cols), x, getNumThreads()); |
|
|
|
ParallelGradientDericheYRows xr(planTmp[i], planDst[i], alphaMean); |
|
|
|
ParallelGradientDericheYRows xr(planTmp[i], planDst[i], alphaDerive, omega); |
|
|
|
parallel_for_(Range(0, planTmp[i].rows), xr, getNumThreads()); |
|
|
|
parallel_for_(Range(0, planTmp[i].rows), xr, getNumThreads()); |
|
|
|
} |
|
|
|
} |
|
|
|
merge(planDst, _dst); |
|
|
|
merge(planDst, _dst); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GradientDericheX(InputArray _op, OutputArray _dst, double alphaDerive, double alphaMean) |
|
|
|
void GradientDericheX(InputArray _op, OutputArray _dst, double alpha, double omega) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<Mat> planSrc; |
|
|
|
std::vector<Mat> planSrc; |
|
|
|
split(_op, planSrc); |
|
|
|
split(_op, planSrc); |
|
|
@ -435,9 +447,9 @@ void GradientDericheX(InputArray _op, OutputArray _dst, double alphaDerive, doub |
|
|
|
planDst.push_back(Mat(_op.size(), CV_32FC1)); |
|
|
|
planDst.push_back(Mat(_op.size(), CV_32FC1)); |
|
|
|
CV_Assert(planSrc[i].isContinuous() && planTmp[i].isContinuous() && planDst[i].isContinuous()); |
|
|
|
CV_Assert(planSrc[i].isContinuous() && planTmp[i].isContinuous() && planDst[i].isContinuous()); |
|
|
|
|
|
|
|
|
|
|
|
ParallelGradientDericheXRows x(planSrc[i], planTmp[i], alphaDerive); |
|
|
|
ParallelGradientDericheXRows x(planSrc[i], planTmp[i], alpha, omega); |
|
|
|
parallel_for_(Range(0, planSrc[i].rows), x, getNumThreads()); |
|
|
|
parallel_for_(Range(0, planSrc[i].rows), x, getNumThreads()); |
|
|
|
ParallelGradientDericheXCols xr(planTmp[i], planDst[i], alphaMean); |
|
|
|
ParallelGradientDericheXCols xr(planTmp[i], planDst[i], alpha, omega); |
|
|
|
parallel_for_(Range(0, planTmp[i].cols), xr, getNumThreads()); |
|
|
|
parallel_for_(Range(0, planTmp[i].cols), xr, getNumThreads()); |
|
|
|
} |
|
|
|
} |
|
|
|
merge(planDst, _dst); |
|
|
|
merge(planDst, _dst); |
|
|
|