Skip to content

Conversation

cookpa
Copy link
Contributor

@cookpa cookpa commented Jun 9, 2025

Fixing #5358

I updated the ITK test to check the determinants after permuting or flipping the index space, and updating the header to compensate. I think I've done this correctly, at least I can now get the same answer as with an identity transform.

I did some more tests in some sample data I made for debugging ANTs jacobians (linked in the issue).

This PR makes the filter more comparable to what you would get by iterating over the displacement field voxels and calling the ComputeJacobianWithRespectToPosition function at each point. It's not exactly the same, because the finite difference sampling scheme is not the same, although the filter allows users to set custom weights, so maybe it could be made more similar.

One other thing (which I can fix): in the test, the seeming typo variable name "dispacementfield" was used throughout one function, I thought it might be intentional, so I didn't change it. But happy to update if needed.

@github-actions github-actions bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module labels Jun 9, 2025
@dzenanz dzenanz requested a review from N-Dekker June 10, 2025 14:12
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this. I did not have a good look. I still have some remarks.

@cookpa
Copy link
Contributor Author

cookpa commented Jun 10, 2025

Thanks, I'll update on both of these points

@thewtex thewtex requested a review from ntustison June 11, 2025 14:19
@blowekamp
Copy link
Member

@hjmjohnson Why are we merging main into branches. I thought our standard work flow was to rebase, to avoid an ugly commit history to extraneous merges?

@hjmjohnson hjmjohnson force-pushed the fix_jac_determinant branch from 9dd0051 to 5f0446b Compare August 13, 2025 15:29
@hjmjohnson
Copy link
Member

@hjmjohnson Why are we merging main into branches. I thought our standard work flow was to rebase, to avoid an ugly commit history to extraneous merges?

It was a mistake. It tried using "gh pr update-branch" which did not do what I wanted.

I have re-pushed the changes without the merge.

cookpa added 3 commits August 14, 2025 07:59
The gradient is calculated in a neighborhood defined in index space.

DisplacementFieldTransform accounts for this by multiplying rows of the
gradient by the direction matrix. DisplacementFieldJacobianDeterminantFilter did not,
hence its determinants were different for the same physical transformation under different
voxel index ordering.

DisplacementFieldJacobianDeterminantFilter is now fixed to use the direction matrix.

The test is updated to check that the determinant for a given displacement field is consistent
at the same point in physical space, regardless of how the index space is oriented.

More details in issue InsightSoftwareConsortium#5358.
@hjmjohnson hjmjohnson force-pushed the fix_jac_determinant branch from 5f0446b to b084fc0 Compare August 14, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Filtering Issues affecting the Filtering module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants