ANTsPy: Possible bug in deformation_gradient rotations with py_based=True
Thanks for adding the polar decomposition tests (#818) @ntustison.
The reason I was doubting it was because the tensor reorientation in antspymm appeared to be working despite using the jacobian of the warp field and not its inverse, which was puzzling me. I think the answer might be in the “py_based” part of the computation:
This bypasses CreateJacobianDeterminantImage and computes the gradient itself.
However, it does not produce the gradient in physical space - it does the same thing that the ANTs filter was doing:
This applies the direction matrix to the displacement vectors that are already in physical space. In the case of a diagonal direction matrix, the direction is its own inverse so this does a rebase of the vectors to index coordinates - it doesn’t change the magnitude into voxels, but that gets accounted for in the gradient calculation. If the fixed image was oblique, applying the direction matrix in this way rotates the vectors into a new coordinate system, which is one reason why CreateJacobianDeterminantImage was giving wrong answers on oblique images.
So the rotations returned by the py_based method are in index coordinates. In the antspymm tests, the direction matrix is very close to diag(-1, -1, 1), so the rotation about z in index space is (I think) equivalent to the opposite rotation in physical space, so it appears to work.
I’ll try to confirm later with further DT reorientation tests @stnava
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (17 by maintainers)
@cookpa – I was not sure where to put this but I think this vectorized implementation is both correct and much faster. also relevant to : https://github.com/ANTsX/ANTsPyMM/issues/27