diff --git a/nitransforms/manip.py b/nitransforms/manip.py index 95090007..6f2f26a3 100644 --- a/nitransforms/manip.py +++ b/nitransforms/manip.py @@ -156,6 +156,16 @@ def asaffine(self, indices=None): [0., 0., 1., 0.], [0., 0., 0., 1.]]) + >>> 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.]]) + Parameters ---------- indices : :obj:`numpy.array_like` @@ -163,8 +173,8 @@ def asaffine(self, indices=None): """ affines = self.transforms if indices is None else np.take(self.transforms, indices) - retval = affines[0] - for xfm in affines[1:]: + retval = affines[-1] + for xfm in reversed(affines[:-1]): retval @= xfm return retval