Skip to content

Commit

Permalink
Merge pull request #206 from chrisfilo/enh/reorient
Browse files Browse the repository at this point in the history
[RTM] use nibabel to reorient to avoid unecessary interpolation
  • Loading branch information
chrisgorgo committed Dec 5, 2016
2 parents 704678a + ceb4c63 commit f96e7cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 9 additions & 0 deletions fmriprep/interfaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ def _tsv_format(translations, rot_angles, fmt='confounds'):

return out_file


def reorient(in_file):
import os
import nibabel as nb

_, outfile = os.path.split(in_file)
nii = nb.as_closest_canonical(nb.load(in_file))
nii.to_filename(outfile)
return os.path.abspath(outfile)
6 changes: 4 additions & 2 deletions fmriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os.path as op

from nipype.interfaces import ants
from nipype.interfaces import freesurfer as fs
from nipype.interfaces import fsl
from nipype.interfaces import io as nio
from nipype.interfaces import utility as niu
Expand All @@ -25,6 +24,7 @@

from fmriprep.interfaces import (DerivativesDataSink, IntraModalMerge,
ImageDataSink)
from fmriprep.interfaces.utils import reorient
from fmriprep.viz import stripped_brain_overlay


Expand All @@ -47,7 +47,9 @@ def t1w_preprocessing(name='t1w_preprocessing', settings=None):
t1wmrg = pe.Node(IntraModalMerge(), name='MergeT1s')

# 1. Reorient T1
arw = pe.Node(fs.MRIConvert(out_type='niigz', out_orientation='LAS'),
arw = pe.Node(niu.Function(input_names=['in_file'],
output_names=['out_file'],
function=reorient),
name='Reorient')

# 2. T1 Bias Field Correction
Expand Down
16 changes: 8 additions & 8 deletions fmriprep/workflows/sbref.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from nipype.interfaces import io as nio
from nipype.interfaces import utility as niu
from nipype.interfaces import fsl, c3
from nipype.interfaces import freesurfer as fs
from nipype.interfaces import ants
from niworkflows.interfaces.masks import BETRPT
from niworkflows.interfaces.registration import FLIRTRPT

from fmriprep.utils.misc import _first, gen_list
from fmriprep.interfaces.utils import reorient
from fmriprep.interfaces import (ReadSidecarJSON, IntraModalMerge,
DerivativesDataSink, ImageDataSink)
from fmriprep.workflows.fieldmap import sdc_unwarp
Expand Down Expand Up @@ -135,10 +135,10 @@ def sbref_t1_registration(name='SBrefSpatialNormalization', settings=None):
)

# Make sure sbref is in RAS coordinates
reorient = pe.Node(
fs.MRIConvert(out_type='niigz', out_orientation='RAS'),
name='SBRefReorient'
)
to_ras = pe.Node(niu.Function(input_names=['in_file'],
output_names=['out_file'],
function=reorient),
name='SBRefReorient')

# Extract wm mask from segmentation
wm_mask = pe.Node(
Expand All @@ -159,12 +159,12 @@ def sbref_t1_registration(name='SBrefSpatialNormalization', settings=None):
invt_bbr = pe.Node(fsl.ConvertXFM(invert_xfm=True), name="Flirt_BBR_Inv")

workflow.connect([
(inputnode, reorient, [('sbref_brain', 'in_file')]),
(inputnode, to_ras, [('sbref_brain', 'in_file')]),
(inputnode, wm_mask, [('t1_seg', 'in_file')]),
(inputnode, flt_bbr_init, [('t1_brain', 'reference')]),
(inputnode, flt_bbr, [('t1_brain', 'reference')]),
(reorient, flt_bbr_init, [('out_file', 'in_file')]),
(reorient, flt_bbr, [('out_file', 'in_file')]),
(to_ras, flt_bbr_init, [('out_file', 'in_file')]),
(to_ras, flt_bbr, [('out_file', 'in_file')]),
(flt_bbr_init, flt_bbr, [('out_matrix_file', 'in_matrix_file')]),
(wm_mask, flt_bbr, [('out_file', 'wm_seg')]),
(flt_bbr, invt_bbr, [('out_matrix_file', 'in_file')]),
Expand Down

0 comments on commit f96e7cf

Please sign in to comment.