Skip to content

Commit 5822b41

Browse files
committed
FIX: Reverse ordering of ITK composite h5 files for TransformChain
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 #81.
1 parent e5a6b41 commit 5822b41

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

nitransforms/manip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def map(self, x, inverse=False):
131131
raise TransformError("Cannot apply an empty transforms chain.")
132132

133133
transforms = self.transforms
134-
if not inverse:
135-
transforms = self.transforms[::-1]
134+
if inverse:
135+
transforms = list(reversed(self.transforms))
136136

137137
for xfm in transforms:
138138
x = xfm(x, inverse=inverse)
@@ -157,9 +157,9 @@ def from_filename(cls, filename, fmt="X5", reference=None, moving=None):
157157
xforms = itk.ITKCompositeH5.from_filename(filename)
158158
for xfmobj in xforms:
159159
if isinstance(xfmobj, itk.ITKLinearTransform):
160-
retval.append(Affine(xfmobj.to_ras(), reference=reference))
160+
retval.insert(0, Affine(xfmobj.to_ras(), reference=reference))
161161
else:
162-
retval.append(DisplacementsFieldTransform(xfmobj))
162+
retval.insert(0, DisplacementsFieldTransform(xfmobj))
163163

164164
return TransformChain(retval)
165165

0 commit comments

Comments
 (0)