Skip to content

Commit

Permalink
FIX: Reverse ordering of ITK composite h5 files for TransformChain
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oesteban committed Jul 18, 2022
1 parent e5a6b41 commit 5822b41
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nitransforms/manip.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def map(self, x, inverse=False):
raise TransformError("Cannot apply an empty transforms chain.")

transforms = self.transforms
if not inverse:
transforms = self.transforms[::-1]
if inverse:
transforms = list(reversed(self.transforms))

for xfm in transforms:
x = xfm(x, inverse=inverse)
Expand All @@ -157,9 +157,9 @@ def from_filename(cls, filename, fmt="X5", reference=None, moving=None):
xforms = itk.ITKCompositeH5.from_filename(filename)
for xfmobj in xforms:
if isinstance(xfmobj, itk.ITKLinearTransform):
retval.append(Affine(xfmobj.to_ras(), reference=reference))
retval.insert(0, Affine(xfmobj.to_ras(), reference=reference))
else:
retval.append(DisplacementsFieldTransform(xfmobj))
retval.insert(0, DisplacementsFieldTransform(xfmobj))

return TransformChain(retval)

Expand Down

0 comments on commit 5822b41

Please sign in to comment.