8000 Strange Formulas in ridge flow computation · Issue #391 · usnistgov/NFIQ2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Strange Formulas in ridge flow computation #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
utcke opened this issue Mar 5, 2025 · 2 comments
Open

Strange Formulas in ridge flow computation #391

utcke opened this issue Mar 5, 2025 · 2 comments

Comments

@utcke
Copy link
utcke commented Mar 5, 2025

Have not checked this against the code yet, but in 6.1.5.4 we see strange formulas.

The usual explanation for the ridge flow computation is to compute the local gradient at each pixel (f_x anf f_y), then, purely for mathematical purposes, combine that into an imaginary number:

g = f_x + i f_y = R e^{i\phi}

The reason for this is that we actually do not care if the gradient is from light to dark, or from dark to light, so \phi and \phi+180° should be considered the same orientation. Simple example:

||||||| <- is the maximum gradient from left to right or from right to left?

The easiest way to achieve this is multiplying the angle by two: 2\phi = 2(\phi+180°) = 2\phi + 360° = 2\phi
And imaginary numbers have the nice property that squaring the number doubles the angle, so we get:

g^2 = R^2 e^{i 2\phi} = (f_x + i f_y)^2 = (f_x^2 - f_y^2) + i (2 f_x f_y) = R^2 + e^{i 2 \phi}

so calculating the mean of all these (squared) gradients results in

\overbar(g^2} = \overbar{f_x^2} - \overbar{f_y^2} + i 2 \overbar{f_x f_y} = R'^2 e^{i 2 \phi'}

or, using equations (5), (6), and (7)

\overbar{g^2} = a-b + i 2c = \sqrt{(a-b)^2+4c^2} e^{i \atan(2c/(a-b))}

or R = \sqrt{(a-b)^2+4c^2}

which is nearly (9), except for the factor 4, and

\phi = 1/2\atan(2c/(a-b))

which is nearly (12), except for the factor 2.

(10) and (11) aren't actually needed, but if we wanted to use them, they had to be

\sin(\theta)=2c/R
\cos(\theta) = (a-b)/R

and (8) will be only needed later, but this is the scatter matrix of the gradient and is, I believe, correct.

BTW, in (13) and (14), which use (8), you will see that \lambda = ((a+b)\pm R)/2,

and calculating the eigenvectors from the eigenvalues given in (13) and (14) and using the identity

\tan(2a) = 2\tan(a)/(1-\tan^2(a))

you would ultimately arrive at the same angle.

@utcke
Copy link
Author
utcke commented Mar 5, 2025

Image

As you can see the difference is small enough that this might not have been an issue...

To clarify: The error is below 10°, so might not have been immediately noticeable, but the results will definitely be wrong, unless c happens to be 0.

@utcke
Copy link
Author
utcke commented Mar 17, 2025

common_functions.cpp:L240 evaluates equations (9)-(12). Whether those are correct depends on the value provided for c, so we need to look at the position that calls NFIQ2::QualityMeasures::ridgeorient().

Looking at the definition of covcoef() in common_functions.cpp:L151 I can see that c is indeed calculated as in (7), so a factor of 2 is missing from all of the above usages, or, alternatively, the definition of ridgeorient()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0