-
Notifications
You must be signed in to change notification settings - Fork 16
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
ENH: API change in TransformChain
- new composition convention
#165
Conversation
This PR makes the ``TransformChain`` class more consistent with the overall coordinate system, assuming that transforms are chained with the *points* criteria. In other words, in the typical setup where we have estimated one initializing affine and then perhaps two levels of nonlinear deformations, when calculating the coordinates of a given index in the reference image, the last nonlinear should be applied first, then the second, and finally the affine to pull information from the moving image. In other words, the chaining (composition) operation works exactly as a single transformation procedure. Resolves nipy#81.
unit tests are your friend Resolves: nipy#81.
Codecov Report
@@ Coverage Diff @@
## master #165 +/- ##
=======================================
Coverage 98.54% 98.55%
=======================================
Files 13 13
Lines 1169 1177 +8
Branches 184 184
=======================================
+ Hits 1152 1160 +8
Misses 10 10
Partials 7 7
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
2edfce6
to
533a03d
Compare
If I'm getting this right, we had previously adopted the ITK last-in-first-out ordering of transform chains (I'm guessing this was because our exemplar of transform chains occurring within a file.) and now we would like it to be more intuitively left-to-right, moving-to-fixed? If so, is this more of an API change than a fix? I would also use a different test for chaining. You currently are just showing that two inverse matrices cancel out, when something that will fail if we get the order wrong would be something like: >>> chain = TransformChain(transforms=[
... Affine.from_matvec(vec=(1, 2, 3)),
... Affine.from_matvec(mat=[[0, 1, 0], [0, 0, 1], [1, 0, 0]]),
... ])
>>> chain.asaffine()
array([[0., 1., 0., 2.],
[0., 0., 1., 3.],
[1., 0., 0., 1.],
[0., 0., 0., 1.]]) I think that should be right, since rotation after translation will rotate the translation parameters... Speaking of which, since you have two implementations of the ordering, I think we need to verify consistency: def test_consistency():
affine_chain = ...
coords = ...
chain_mapped = affine_chain.map(coords)
affine_mapped = Affine(affine_chain.asaffine()).map(coords)
assert np.allclose(chain_mapped, affine_mapped) |
Yes, I think this is a good summary -- although the convention proposed in the PR I believe should be called right-to-left, fixed-to-moving, as in the actual transformation equations: where EDIT: forgot to mention that the subscript
Yes.
I'll add your test :) That said, there is a test that failed when I just updated the API - see 7f1657c The test failed because I hadn't updated it to the new ordering.
If there are two different implementations of the ordering, that's my bad -- that shouldn't be. However, now I realize that the Instead, there should be just a |
66bd6b2
to
f8b592f
Compare
Thanks Chris for pointing this out. Co-authored-by: Chris Markiewicz <[email protected]>
f8b592f
to
e80bd3c
Compare
TransformChain
TransformChain
- new composition convention
Since |
With ITK, it does a stack, e.g., |
Just opened the issue above to make sure this does not fall through the cracks. |
This PR makes the
TransformChain
class more consistent with theoverall coordinate system, assuming that transforms are chained with the
points criteria.
In other words, in the typical setup where we have estimated one
initializing affine and then perhaps two levels of nonlinear
deformations, when calculating the coordinates of a given index in the
reference image, the last nonlinear should be applied first, then the
second, and finally the affine to pull information from the moving
image.
In other words, the chaining (composition) operation works exactly as
a single transformation procedure.
Resolves #81.