File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,17 @@ def from_image(cls, imgobj):
193
193
194
194
return imgobj .__class__ (field , imgobj .affine , hdr )
195
195
196
+ @classmethod
197
+ def to_image (cls , imgobj ):
198
+ """Export a displacements field from a nibabel object."""
199
+
200
+ hdr = imgobj .header .copy ()
201
+
202
+ warp_data = imgobj .get_fdata ().reshape (imgobj .shape [:3 ] + (1 , imgobj .shape [- 1 ]))
203
+ warp_data [..., (0 , 1 )] *= - 1
204
+
205
+ return imgobj .__class__ (warp_data , imgobj .affine , hdr )
206
+
196
207
197
208
def _is_oblique (affine , thres = OBLIQUITY_THRESHOLD_DEG ):
198
209
"""
Original file line number Diff line number Diff line change @@ -146,6 +146,17 @@ def from_image(cls, imgobj):
146
146
"""Import a displacements field from a nibabel image object."""
147
147
raise NotImplementedError
148
148
149
+ @classmethod
150
+ def to_filename (cls , img , filename ):
151
+ """Export a displacements field to a NIfTI file."""
152
+ imgobj = cls .to_image (img )
153
+ imgobj .to_filename (filename )
154
+
155
+ @classmethod
156
+ def to_image (cls , imgobj ):
157
+ """Export a displacements field image from a nitransforms image object."""
158
+ raise NotImplementedError
159
+
149
160
150
161
def _ensure_image (img ):
151
162
if isinstance (img , (str , Path )):
Original file line number Diff line number Diff line change @@ -190,6 +190,17 @@ def from_image(cls, imgobj):
190
190
191
191
return imgobj .__class__ (field , imgobj .affine , hdr )
192
192
193
+ @classmethod
194
+ def to_image (cls , imgobj ):
195
+ """Export a displacements field from a nibabel object."""
196
+
197
+ hdr = imgobj .header .copy ()
198
+
199
+ warp_data = imgobj .get_fdata ()
200
+ warp_data [..., 0 ] *= - 1
201
+
202
+ return imgobj .__class__ (warp_data , imgobj .affine , hdr )
203
+
193
204
194
205
def _fsl_aff_adapt (space ):
195
206
"""
Original file line number Diff line number Diff line change @@ -352,6 +352,18 @@ def from_image(cls, imgobj):
352
352
353
353
return imgobj .__class__ (field , imgobj .affine , hdr )
354
354
355
+ @classmethod
356
+ def to_image (cls , imgobj ):
357
+ """Export a displacements field from a nibabel object."""
358
+
359
+ hdr = imgobj .header .copy ()
360
+ hdr .set_intent ("vector" )
361
+
362
+ warp_data = imgobj .get_fdata ().reshape (imgobj .shape [:3 ] + (1 , imgobj .shape [- 1 ]))
363
+ warp_data [..., (0 , 1 )] *= - 1
364
+
365
+ return imgobj .__class__ (warp_data , imgobj .affine , hdr )
366
+
355
367
356
368
class ITKCompositeH5 :
357
369
"""A data structure for ITK's HDF5 files."""
You can’t perform that action at this time.
0 commit comments