Skip to content
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

Fix the order of return values for hessian_matrix #6624

Merged
merged 5 commits into from Jan 18, 2023

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Nov 20, 2022

closes #5230

This fixes the reported bug where 'xy' order was returned when 'rc' was requested and vice-versa. The change here also matrix hessian_matrix order consistent with structure_tensor which has the same conventions.

A second inconsistency is that structure_tensor only allows use of mode='xy' for 2D images and otherwise raises an error, while hessian_matrix did not have this restriction. I have changed the hessian_matrix behavior here for consistency.

Fortunately, the presence of this bug did not effect the use cases of this function in higher order functions within scikit-image (e.g. blob_doh and various ridge filters like sato, meijering, frangi). The eigenvalues used by the ridge filters, for example, are the same whether or not the axes are reversed.

For mode='rc' the 2nd derivative along axis=0 should come first.
This change also makes the order consistent with that used by structure_tensor
add test cases to confirm expected behavior for order
@grlee77 grlee77 added the 🩹 type: Bug fix Fixes unexpected or incorrect behavior label Nov 20, 2022
@grlee77 grlee77 added this to the 0.20 milestone Nov 20, 2022
@grlee77
Copy link
Contributor Author

grlee77 commented Nov 21, 2022

CI failures are unrelated and fixed by #6626

Copy link
Member

@lagru lagru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nitpicks and maybe we can make a test more specific but otherwise good to go. Thanks @grlee77!

skimage/feature/corner.py Outdated Show resolved Hide resolved
skimage/feature/corner.py Outdated Show resolved Hide resolved
skimage/feature/corner.py Outdated Show resolved Hide resolved
skimage/feature/tests/test_corner.py Show resolved Hide resolved
@stefanv
Copy link
Member

stefanv commented Jan 18, 2023

@lagru Want to make the minor adjustment to the test and merge this?

@lagru
Copy link
Member

lagru commented Jan 18, 2023

Okay, I'll take your #6624 (comment) as an approval.

lagru and others added 2 commits January 18, 2023 10:40
Explanation: Each array in Hs is the result of

    H_elems = [np.gradient(gradients[ax0], axis=ax1)
               for ax0, ax1 in combinations_with_replacement(axes, 2)]

Because reversing axes (due to the bug fix) doesn't affect the result
of `H_elems[2]`. For index 2, `combinations_with_replacement(axes, 2)`
returns either `(0, 2)` or the reversed `(2, 0)`. Both result in the
same gradient.

So to make the test notice this change, we test another one of H_elems
arrays whose result is not the same if axes is reversed.
@lagru lagru merged commit 8233150 into scikit-image:main Jan 18, 2023
@lagru
Copy link
Member

lagru commented Jan 18, 2023

Thanks @grlee77 and @stefanv!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🩹 type: Bug fix Fixes unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong order in hessian_matrix?
3 participants