Moving images from MNI to BOLD/EPI/native space

Hi @oesteban,

I work with Zeynab and we were exploring a quick workaround to look at the data in native space by inverting the transformations.

However, I am having trouble getting antsApplyTransforms to take the affine matrix created by bbregister. I can get the *preproc.nii.gz bold image in MNI space registered to T1 space using the .h5 file. But antsApplyTransforms doesn’t like any of the affine .txt files. I’ve tried using the affine.txt file located in the /fsl2itk/ folder in workflows and the *T1_affine.txt file (inverting it) located in the /anat/ output folder.

Obviously it’s much simpler to just be able to have the native space be the output, but I’m curious as to why the transformations aren’t working.


  • Harris

The command I’m using is

antsApplyTransforms -d 3 -e 3 --input $fmriprepdir/$sub/func/"$sub"_task-rest_bold_space-MNI152NLin2009cAsym_preproc.nii.gz --reference-image $bidsdir/$sub/func/"$sub"_task-rest_bold.nii --output $fmriprepdir/$sub/func/"$sub"_space-nativetest2_preproc.nii.gz /autofs/space/rainier_002/users/harris/CTS/data/BIDS_output/tmp_workdir/fmriprep_wf/single_subject_$subname_wf/func_preproc_task_rest_wf/bold_reg_wf/bbreg_wf/fsl2itk_inv/affine.txt --transform $fmriprepdir/$sub/anat/"$sub"_T1w_space-MNI152NLin2009cAsym_target-T1w_warp.h5 -v 1

and the error message is

terminate called after throwing an instance of 'itk::ImageFileWriterException'
  what():  /autofs/space/rainier_001/users/harris/Sim4Life/antsbin/ITKv4-install/include/ITK-4.12/itkImageFileWriter.hxx:151:
 Could not create IO object for writing file /autofs/space/rainier_002/users/harris/CTS/data/BIDS_output/tmp_workdir/fmriprep_wf/single_subject_HV03baseline_wf/func_preproc_task_rest_wf/bold_reg_wf/bbreg_wf/fsl2itk_inv/affine.txt

Hi @hpfisher3 and @Zeynab .

Before I try to help you with antsApplyTransforms lets make sure that what you are trying to do is the right thing to do.

For people looking for native/EPI/BOLD space in FMRIPREP outputs we recommend using the T1w output space. It is aligned with the participants T1w template which allows for easy derivation of anatomical ROI, uses the resolution of the raw input data (which saves space), and was created using only one interpolation (minimizing smoothing, by combining transforms). There are very few legitimate cases where native/EPI/BOLD space would be needed instead of T1w space.

What you are attempting to do is to go from MNI to native/EPI/BOLD space. This has a few problems:

  • nonlinear transformations can be lossy, multiple voxels are squished into one and reversing this cannot be done without losing some information
  • applying additional interpolation to the data will introduce some smoothing

So why not just use T1w space?

Hi @ChrisGorgolewski,

Thanks for the quick response! Yes, I agree with all the points you raised. Selecting the T1w space as the output would definitely be the way to go if we are hoping to look at native space with fmriprep in its current form.

Mostly I was just trying to check my understanding of how the transformations work and was confused why it wasn’t working, but I’m also thinking about certain cases where one might want to look at a how a group level result from MNI space maps to individual subject spaces. Though based on your points that can probably be done by just transforming back to T1w space rather than all the way back to the original bold space.

Yup - that’s correct.

As for your command line - one thing I see being suspicious is lack of --transform in front of the path to affine.txt.

Yes that was it, left it out somehow. It runs but something isn’t right because the resulting image appears all but completely shifted out of view. Only a small sliver of the brain is visible on the edge of the image.

But it seems to be applying the transforms correctly:
The composite transform comprises the following transforms (in order):

  1. /autofs/space/rainier_002/users/harris/CTS/data/BIDS_output/fmriprep/sub-HV03baseline/anat/sub-HV03baseline_T1w_space-MNI152NLin2009cAsym_target-T1w_warp.h5[0] (type = DisplacementFieldTransform)
  2. /autofs/space/rainier_002/users/harris/CTS/data/BIDS_output/fmriprep/sub-HV03baseline/anat/sub-HV03baseline_T1w_space-MNI152NLin2009cAsym_target-T1w_warp.h5[1] (type = AffineTransform)
  3. /autofs/space/rainier_002/users/harris/CTS/data/BIDS_output/tmp_workdir/fmriprep_wf/single_subject_HV03baseline_wf/func_preproc_task_rest_wf/bold_reg_wf/bbreg_wf/fsl2itk_inv/affine.txt (type = MatrixOffsetTransformBase)

Perhaps the reference is at fault - you might need to dig up the BOLD reference image in the working directory. This is the one that is used for bold<->T1w registration - it might have different sform/qform which could lead to these issues.

Ok got it now. Thanks! I used func_preproc_task_rest_wf/bold_split/vol0001.nii.gz as the reference and it now aligns to the original raw bold perfectly.