File tree 4 files changed +45
-0
lines changed
4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,17 @@ def from_image(cls, imgobj):
209
209
210
210
return imgobj .__class__ (field , imgobj .affine , hdr )
211
211
212
+ @classmethod
213
+ def to_image (cls , imgobj ):
214
+ """Export a displacements field from a nibabel object."""
215
+
216
+ hdr = imgobj .header .copy ()
217
+
218
+ warp_data = imgobj .get_fdata ().reshape (imgobj .shape [:3 ] + (1 , imgobj .shape [- 1 ]))
219
+ warp_data [..., (0 , 1 )] *= - 1
220
+
221
+ return imgobj .__class__ (warp_data , imgobj .affine , hdr )
222
+
212
223
213
224
def _is_oblique (affine , thres = OBLIQUITY_THRESHOLD_DEG ):
214
225
"""
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