Skip to content

Commit 95b0692

Browse files
smoiaoesteban
authored andcommitted
Added FSL Displacement field class and a FSL warp
1 parent 5fb3e40 commit 95b0692

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

nitransforms/io/fsl.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .base import (
1010
BaseLinearTransformList,
1111
LinearParameters,
12+
DisplacementsField,
1213
TransformFileError,
1314
_ensure_image,
1415
)
@@ -171,6 +172,26 @@ def from_filename(cls, filename):
171172
return _self
172173

173174

175+
class FSLDisplacementsField(DisplacementsField):
176+
"""A data structure representing displacements fields."""
177+
178+
@classmethod
179+
def from_image(cls, imgobj):
180+
"""Import a displacements field from a NIfTI file."""
181+
hdr = imgobj.header.copy()
182+
shape = hdr.get_data_shape()
183+
184+
if len(shape) != 4 or not shape[-1] in (2, 3):
185+
raise TransformFileError(
186+
'Displacements field "%s" does not come from FSL.' %
187+
imgobj.file_map['image'].filename)
188+
189+
field = np.squeeze(np.asanyarray(imgobj.dataobj))
190+
field[..., (0, 1)] *= -1.0
191+
192+
return imgobj.__class__(field, imgobj.affine, hdr)
193+
194+
174195
def _fsl_aff_adapt(space):
175196
"""
176197
Adapt FSL affines.
17.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)