@@ -37,7 +37,7 @@ def __init__(self, field, reference=None):
3737 Example
3838 -------
3939 >>> DisplacementsFieldTransform(test_dir / "someones_displacement_field.nii.gz")
40- <(57, 67, 56) field of 3D displacements >
40+ <DisplacementFieldTransform[3D] (57, 67, 56)>
4141
4242 """
4343 super ().__init__ ()
@@ -59,7 +59,7 @@ def __init__(self, field, reference=None):
5959
6060 def __repr__ (self ):
6161 """Beautify the python representation."""
62- return f"<{ self ._field .shape [: 3 ] } field of { self ._field .shape [- 1 ] } D displacements >"
62+ return f"<DisplacementFieldTransform[ { self ._field .shape [- 1 ] } D] { self ._field .shape [: 3 ] } >"
6363
6464 def map (self , x , inverse = False ):
6565 r"""
@@ -132,7 +132,7 @@ def __init__(self, coefficients, reference=None, order=3):
132132 coefficients = _ensure_image (coefficients )
133133
134134 self ._coeffs = np .asanyarray (coefficients .dataobj )
135- self ._knots = ImageGrid (four_to_three ( coefficients )[ 0 ] )
135+ self ._knots = ImageGrid (coefficients )
136136 self ._weights = None
137137 if reference is not None :
138138 self .reference = reference
@@ -158,9 +158,11 @@ def to_field(self, reference=None, dtype="float32"):
158158 field = np .zeros ((_ref .npoints , ndim ))
159159
160160 for d in range (ndim ):
161+ # 1 x Nvox : (1 x K) @ (K x Nvox)
161162 field [:, d ] = self ._coeffs [..., d ].reshape (- 1 ) @ self ._weights
162163
163- return field .astype (dtype )
164+ return DisplacementsFieldTransform (
165+ field .astype (dtype ).reshape (* _ref .shape , - 1 ), reference = _ref )
164166
165167 def apply (
166168 self ,
@@ -197,10 +199,7 @@ def apply(
197199 )
198200
199201 # If locations to be interpolated are on a grid, generate a displacements field
200- return DisplacementsFieldTransform (
201- self .to_field ().reshape ((* (_ref .shape ), - 1 )),
202- reference = _ref ,
203- ).apply (
202+ return self .to_field ().apply (
204203 spatialimage ,
205204 reference = reference ,
206205 order = order ,
@@ -216,7 +215,7 @@ def map(self, x, inverse=False):
216215
217216 .. math::
218217 \mathbf{y} = \mathbf{x} + \Psi^3(\mathbf{k}, \mathbf{x}),
219- \label{eq:2 }\tag{2 }
218+ \label{eq:1 }\tag{1 }
220219
221220 Parameters
222221 ----------
0 commit comments