Skip to content

Commit 09af9e0

Browse files
committed
RF: Use nipype.interfaces.image.Reorient
1 parent 5747a6d commit 09af9e0

File tree

3 files changed

+5
-50
lines changed

3 files changed

+5
-50
lines changed

fmriprep/interfaces/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ReadSidecarJSON, DerivativesDataSink, BIDSDataGrabber, BIDSFreeSurferDir, BIDSInfo
66
)
77
from .images import (
8-
IntraModalMerge, InvertT1w, ValidateImage, TemplateDimensions, Conform, Reorient
8+
IntraModalMerge, InvertT1w, ValidateImage, TemplateDimensions, Conform
99
)
1010
from .freesurfer import (
1111
StructuralReference, MakeMidthickness, FSInjectBrainExtracted,

fmriprep/interfaces/images.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -291,52 +291,6 @@ def _run_interface(self, runtime):
291291
return runtime
292292

293293

294-
class ReorientInputSpec(BaseInterfaceInputSpec):
295-
in_file = File(exists=True, mandatory=True,
296-
desc='Input T1w image')
297-
298-
299-
class ReorientOutputSpec(TraitedSpec):
300-
out_file = File(exists=True, desc='Reoriented T1w image')
301-
transform = File(exists=True, desc='Reorientation transform')
302-
303-
304-
class Reorient(SimpleInterface):
305-
"""Reorient a T1w image to RAS (left-right, posterior-anterior, inferior-superior)
306-
307-
Syncs qform and sform codes for consistent treatment by all software
308-
"""
309-
input_spec = ReorientInputSpec
310-
output_spec = ReorientOutputSpec
311-
312-
def _run_interface(self, runtime):
313-
# Load image, orient as RAS
314-
fname = self.inputs.in_file
315-
orig_img = nb.load(fname)
316-
reoriented = nb.as_closest_canonical(orig_img)
317-
318-
# Reconstruct transform from orig to reoriented image
319-
ornt_xfm = nb.orientations.inv_ornt_aff(
320-
nb.io_orientation(orig_img.affine), orig_img.shape)
321-
322-
normalized = normalize_xform(reoriented)
323-
324-
# Image may be reoriented
325-
if normalized is not orig_img:
326-
out_name = fname_presuffix(fname, suffix='_ras', newpath=runtime.cwd)
327-
normalized.to_filename(out_name)
328-
else:
329-
out_name = fname
330-
331-
mat_name = fname_presuffix(fname, suffix='.mat', newpath=runtime.cwd, use_ext=False)
332-
np.savetxt(mat_name, ornt_xfm, fmt='%.08f')
333-
334-
self._results['out_file'] = out_name
335-
self._results['transform'] = mat_name
336-
337-
return runtime
338-
339-
340294
class ValidateImageInputSpec(BaseInterfaceInputSpec):
341295
in_file = File(exists=True, mandatory=True, desc='input image')
342296

fmriprep/workflows/anatomical.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
utility as niu,
3131
c3,
3232
freesurfer as fs,
33-
fsl
33+
fsl,
34+
image,
3435
)
3536
from nipype.interfaces.ants import BrainExtraction, N4BiasFieldCorrection
3637

@@ -43,7 +44,7 @@
4344

4445
from ..interfaces import (
4546
DerivativesDataSink, MakeMidthickness, FSInjectBrainExtracted,
46-
FSDetectInputs, NormalizeSurf, GiftiNameSource, TemplateDimensions, Conform, Reorient,
47+
FSDetectInputs, NormalizeSurf, GiftiNameSource, TemplateDimensions, Conform,
4748
ConcatAffines, RefineBrainMask,
4849
)
4950
from ..utils.misc import fix_multi_T1w_source_name, add_suffix
@@ -481,7 +482,7 @@ def _get_first(in_list):
481482
name='t1_merge')
482483

483484
# 2. Reorient template to RAS, if needed (mri_robust_template may set to LIA)
484-
t1_reorient = pe.Node(Reorient(), name='t1_reorient')
485+
t1_reorient = pe.Node(image.Reorient(), name='t1_reorient')
485486

486487
lta_to_fsl = pe.MapNode(fs.utils.LTAConvert(out_fsl=True), iterfield=['in_lta'],
487488
name='lta_to_fsl')

0 commit comments

Comments
 (0)