Skip to content

Commit

Permalink
Merge pull request #1153 from effigies/rf/upstream_reorient
Browse files Browse the repository at this point in the history
RF: Use nipype.interfaces.image.Reorient
  • Loading branch information
oesteban committed Jun 1, 2018
2 parents 5747a6d + 09af9e0 commit 0341ed7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 50 deletions.
2 changes: 1 addition & 1 deletion fmriprep/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ReadSidecarJSON, DerivativesDataSink, BIDSDataGrabber, BIDSFreeSurferDir, BIDSInfo
)
from .images import (
IntraModalMerge, InvertT1w, ValidateImage, TemplateDimensions, Conform, Reorient
IntraModalMerge, InvertT1w, ValidateImage, TemplateDimensions, Conform
)
from .freesurfer import (
StructuralReference, MakeMidthickness, FSInjectBrainExtracted,
Expand Down
46 changes: 0 additions & 46 deletions fmriprep/interfaces/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,52 +291,6 @@ def _run_interface(self, runtime):
return runtime


class ReorientInputSpec(BaseInterfaceInputSpec):
in_file = File(exists=True, mandatory=True,
desc='Input T1w image')


class ReorientOutputSpec(TraitedSpec):
out_file = File(exists=True, desc='Reoriented T1w image')
transform = File(exists=True, desc='Reorientation transform')


class Reorient(SimpleInterface):
"""Reorient a T1w image to RAS (left-right, posterior-anterior, inferior-superior)
Syncs qform and sform codes for consistent treatment by all software
"""
input_spec = ReorientInputSpec
output_spec = ReorientOutputSpec

def _run_interface(self, runtime):
# Load image, orient as RAS
fname = self.inputs.in_file
orig_img = nb.load(fname)
reoriented = nb.as_closest_canonical(orig_img)

# Reconstruct transform from orig to reoriented image
ornt_xfm = nb.orientations.inv_ornt_aff(
nb.io_orientation(orig_img.affine), orig_img.shape)

normalized = normalize_xform(reoriented)

# Image may be reoriented
if normalized is not orig_img:
out_name = fname_presuffix(fname, suffix='_ras', newpath=runtime.cwd)
normalized.to_filename(out_name)
else:
out_name = fname

mat_name = fname_presuffix(fname, suffix='.mat', newpath=runtime.cwd, use_ext=False)
np.savetxt(mat_name, ornt_xfm, fmt='%.08f')

self._results['out_file'] = out_name
self._results['transform'] = mat_name

return runtime


class ValidateImageInputSpec(BaseInterfaceInputSpec):
in_file = File(exists=True, mandatory=True, desc='input image')

Expand Down
7 changes: 4 additions & 3 deletions fmriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
utility as niu,
c3,
freesurfer as fs,
fsl
fsl,
image,
)
from nipype.interfaces.ants import BrainExtraction, N4BiasFieldCorrection

Expand All @@ -43,7 +44,7 @@

from ..interfaces import (
DerivativesDataSink, MakeMidthickness, FSInjectBrainExtracted,
FSDetectInputs, NormalizeSurf, GiftiNameSource, TemplateDimensions, Conform, Reorient,
FSDetectInputs, NormalizeSurf, GiftiNameSource, TemplateDimensions, Conform,
ConcatAffines, RefineBrainMask,
)
from ..utils.misc import fix_multi_T1w_source_name, add_suffix
Expand Down Expand Up @@ -481,7 +482,7 @@ def _get_first(in_list):
name='t1_merge')

# 2. Reorient template to RAS, if needed (mri_robust_template may set to LIA)
t1_reorient = pe.Node(Reorient(), name='t1_reorient')
t1_reorient = pe.Node(image.Reorient(), name='t1_reorient')

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

0 comments on commit 0341ed7

Please sign in to comment.