Skip to content

[RTM] Switch to composite transforms. #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ What's new
0.3.0 (upcoming)
================

* [FIX] Affine and warp MNI transforms are now applied in the correct order
* [ENH] Added preliminary support for reconstruction of cortical surfaces using FreeSurfer
* [ENH] Switched to bbregister for BOLD to T1 coregistration
* [ENH] Switched to sinc interpolation of preprocessed BOLD and T1w outputs
Expand Down
3 changes: 1 addition & 2 deletions docs/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ Derivatives related to t1w files are in the ``anat`` subfolder:
- ``*T1w_dtissue.nii.gz`` Tissue class map derived using FAST.
- ``*T1w_preproc.nii.gz`` Bias field corrected t1w file, using ANTS' N4BiasFieldCorrection
- ``*T1w_space-MNI152NLin2009cAsym_preproc.nii.gz`` Same as above, but in MNI space
- ``*T1w_target-MNI152NLin2009cAsym_affine.mat`` The affine matrix to transform T1w into MNI space
- ``*T1w_space-MNI152NLin2009cAsym_class-CSF_probtissue.nii.gz``
- ``*T1w_space-MNI152NLin2009cAsym_class-GM_probtissue.nii.gz``
- ``*T1w_space-MNI152NLin2009cAsym_class-WM_probtissue.nii.gz`` Probability tissue maps, transformed into MNI space
- ``*T1w_target-MNI152NLin2009cAsym_warp.nii.gz`` Warp transform to transform t1w into MNI space
- ``*T1w_target-MNI152NLin2009cAsym_warp.h5`` Composite (warp and affine) transform to transform t1w into MNI space

Derivatives related to EPI files are in the ``func`` subfolder:

Expand Down
50 changes: 14 additions & 36 deletions fmriprep/workflows/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ def inject_skullstripped(subjects_dir, subject_id, skullstripped):

# Resample the brain mask and the tissue probability maps into mni space
bmask_mni = pe.Node(
ants.ApplyTransforms(dimension=3, default_value=0,
ants.ApplyTransforms(dimension=3, default_value=0, float=True,
interpolation='NearestNeighbor'),
name='brain_mni_warp'
)
bmask_mni.inputs.reference_image = op.join(get_mni_icbm152_nlin_asym_09c(),
'1mm_T1.nii.gz')
tpms_mni = pe.MapNode(
ants.ApplyTransforms(dimension=3, default_value=0,
ants.ApplyTransforms(dimension=3, default_value=0, float=True,
interpolation='Linear'),
iterfield=['input_image'],
name='tpms_mni_warp'
Expand Down Expand Up @@ -233,16 +233,13 @@ def inject_skullstripped(subjects_dir, subject_id, skullstripped):
(t1_seg, outputnode, [('probability_maps', 't1_tpms')]),
(t1_2_mni, outputnode, [
('warped_image', 't1_2_mni'),
('forward_transforms', 't1_2_mni_forward_transform'),
('reverse_transforms', 't1_2_mni_reverse_transform')
('composite_transform', 't1_2_mni_forward_transform'),
('inverse_composite_transform', 't1_2_mni_reverse_transform')
]),
(asw, bmask_mni, [('outputnode.out_mask', 'input_image')]),
(t1_2_mni, bmask_mni, [('forward_transforms', 'transforms'),
('forward_invert_flags',
'invert_transform_flags')]),
(t1_2_mni, bmask_mni, [('composite_transform', 'transforms')]),
(t1_seg, tpms_mni, [('probability_maps', 'input_image')]),
(t1_2_mni, tpms_mni, [('forward_transforms', 'transforms'),
('forward_invert_flags', 'invert_transform_flags')]),
(t1_2_mni, tpms_mni, [('composite_transform', 'transforms')]),
(asw, outputnode, [('outputnode.out_file', 't1_brain'),
('outputnode.out_mask', 't1_mask')]),
(inputnode, ds_t1_seg_report, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
Expand Down Expand Up @@ -311,11 +308,6 @@ def inject_skullstripped(subjects_dir, subject_id, skullstripped):
suffix='space-MNI152NLin2009cAsym_preproc'),
name='DerivT1w_MNI'
)
ds_t1_mni_aff = pe.Node(
DerivativesDataSink(base_directory=settings['output_dir'],
suffix='target-MNI152NLin2009cAsym_affine'),
name='DerivT1w_MNI_affine'
)
ds_bmask_mni = pe.Node(
DerivativesDataSink(base_directory=settings['output_dir'],
suffix='space-MNI152NLin2009cAsym_brainmask'),
Expand All @@ -328,35 +320,21 @@ def inject_skullstripped(subjects_dir, subject_id, skullstripped):
)
ds_tpms_mni.inputs.extra_values = ['CSF', 'GM', 'WM']

if settings.get('debug', False):
workflow.connect([
(t1_2_mni, ds_t1_mni_aff, [('forward_transforms', 'in_file')])
])
else:
ds_t1_mni_warp = pe.Node(
DerivativesDataSink(base_directory=settings['output_dir'],
suffix='target-MNI152NLin2009cAsym_warp'), name='mni_warp')

def _get_aff(inlist):
return inlist[:-1]

def _get_warp(inlist):
return inlist[-1]
ds_t1_mni_warp = pe.Node(
DerivativesDataSink(base_directory=settings['output_dir'],
suffix='target-MNI152NLin2009cAsym_warp'), name='mni_warp')

workflow.connect([
(inputnode, ds_t1_mni_warp, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(t1_2_mni, ds_t1_mni_aff, [
(('forward_transforms', _get_aff), 'in_file')]),
(t1_2_mni, ds_t1_mni_warp, [
(('forward_transforms', _get_warp), 'in_file')])
])
workflow.connect([
(inputnode, ds_t1_mni_warp, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(t1_2_mni, ds_t1_mni_warp, [
('composite_transform', 'in_file')])
])

workflow.connect([
(inputnode, ds_t1_bias, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(inputnode, ds_t1_seg, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(inputnode, ds_mask, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(inputnode, ds_t1_mni, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(inputnode, ds_t1_mni_aff, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(inputnode, ds_bmask_mni, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(inputnode, ds_tpms_mni, [(('t1w', fix_multi_T1w_source_name), 'source_file')]),
(asw, ds_t1_bias, [('outputnode.bias_corrected', 'in_file')]),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+https://github.com/nipy/nipype.git@07a75a64ae917b4ed0839d3b5a79bd63ebed9964#egg=nipype
git+https://github.com/poldracklab/niworkflows.git@f3e11159ba8ddc8c850edc3bd1bf62d7286322d4#egg=niworkflows
git+https://github.com/poldracklab/niworkflows.git@8b0f51268f4f5030eac9c2447fb9dea26a312dc0#egg=niworkflows