Skip to content

Commit f9fbd29

Browse files
committed
Merge pull request opencv#18225 from dmici:fix_missing_0.5_factor_in_anisotropic_segmentation_tutorial
2 parents 31dc3e9 + 6876f3b commit f9fbd29

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

doc/tutorials/imgproc/anisotropic_image_segmentation/anisotropic_image_segmentation.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ J_{12} & J_{22}
3737
where \f$J_{11} = M[Z_{x}^{2}]\f$, \f$J_{22} = M[Z_{y}^{2}]\f$, \f$J_{12} = M[Z_{x}Z_{y}]\f$ - components of the tensor, \f$M[]\f$ is a symbol of mathematical expectation (we can consider this operation as averaging in a window w), \f$Z_{x}\f$ and \f$Z_{y}\f$ are partial derivatives of an image \f$Z\f$ with respect to \f$x\f$ and \f$y\f$.
3838

3939
The eigenvalues of the tensor can be found in the below formula:
40-
\f[\lambda_{1,2} = J_{11} + J_{22} \pm \sqrt{(J_{11} - J_{22})^{2} + 4J_{12}^{2}}\f]
40+
\f[\lambda_{1,2} = \frac{1}{2} \left [ J_{11} + J_{22} \pm \sqrt{(J_{11} - J_{22})^{2} + 4J_{12}^{2}} \right ] \f]
4141
where \f$\lambda_1\f$ - largest eigenvalue, \f$\lambda_2\f$ - smallest eigenvalue.
4242

4343
### How to estimate orientation and coherency of an anisotropic image by gradient structure tensor?

samples/cpp/tutorial_code/ImgProc/anisotropic_image_segmentation/anisotropic_image_segmentation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void calcGST(const Mat& inputImg, Mat& imgCoherencyOut, Mat& imgOrientationOut,
7474
// GST components calculation (stop)
7575

7676
// eigenvalue calculation (start)
77-
// lambda1 = J11 + J22 + sqrt((J11-J22)^2 + 4*J12^2)
78-
// lambda2 = J11 + J22 - sqrt((J11-J22)^2 + 4*J12^2)
77+
// lambda1 = 0.5*(J11 + J22 + sqrt((J11-J22)^2 + 4*J12^2))
78+
// lambda2 = 0.5*(J11 + J22 - sqrt((J11-J22)^2 + 4*J12^2))
7979
Mat tmp1, tmp2, tmp3, tmp4;
8080
tmp1 = J11 + J22;
8181
tmp2 = J11 - J22;
@@ -84,8 +84,10 @@ void calcGST(const Mat& inputImg, Mat& imgCoherencyOut, Mat& imgOrientationOut,
8484
sqrt(tmp2 + 4.0 * tmp3, tmp4);
8585

8686
Mat lambda1, lambda2;
87-
lambda1 = tmp1 + tmp4; // biggest eigenvalue
88-
lambda2 = tmp1 - tmp4; // smallest eigenvalue
87+
lambda1 = tmp1 + tmp4;
88+
lambda1 = 0.5*lambda1; // biggest eigenvalue
89+
lambda2 = tmp1 - tmp4;
90+
lambda2 = 0.5*lambda2; // smallest eigenvalue
8991
// eigenvalue calculation (stop)
9092

9193
// Coherency calculation (start)

samples/python/tutorial_code/imgProc/anisotropic_image_segmentation/anisotropic_image_segmentation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ def calcGST(inputIMG, w):
3131
# GST components calculations (stop)
3232

3333
# eigenvalue calculation (start)
34-
# lambda1 = J11 + J22 + sqrt((J11-J22)^2 + 4*J12^2)
35-
# lambda2 = J11 + J22 - sqrt((J11-J22)^2 + 4*J12^2)
34+
# lambda1 = 0.5*(J11 + J22 + sqrt((J11-J22)^2 + 4*J12^2))
35+
# lambda2 = 0.5*(J11 + J22 - sqrt((J11-J22)^2 + 4*J12^2))
3636
tmp1 = J11 + J22
3737
tmp2 = J11 - J22
3838
tmp2 = cv.multiply(tmp2, tmp2)
3939
tmp3 = cv.multiply(J12, J12)
4040
tmp4 = np.sqrt(tmp2 + 4.0 * tmp3)
4141

42-
lambda1 = tmp1 + tmp4 # biggest eigenvalue
43-
lambda2 = tmp1 - tmp4 # smallest eigenvalue
42+
lambda1 = 0.5*(tmp1 + tmp4) # biggest eigenvalue
43+
lambda2 = 0.5*(tmp1 - tmp4) # smallest eigenvalue
4444
# eigenvalue calculation (stop)
4545

4646
# Coherency calculation (start)

0 commit comments

Comments
 (0)