Fmriprep resamples bold images to another voxel dimension/orientation

Hi @effigies, sorry for me being impatient!

I doublechecked but still sent you the information of the T1 instead of the original bold image, sorry. Below you see a screenshot of the python code you suggested, and as a last entry I added the fslhd info, this time really of the original bold image.

I’m using 6 dof BOLD T1w registration according to the html report. Further we just noticed " Note on orientation: qform matrix overwritten. The qform has been copied from sform." -> is this of importance?

Below a try to summarize the different voxel orientation in the different images:

The registration section of the html reports

and finally also screenshots from the Fieldmap to EPI registration, as orientation of the voxel seems to be different again in those.

Sharing a T1w image and volumes of the BOLD series of a healthy control would be possible. I try to get the data today from the MRI just in case. Those bold images are oriented coronal along the hippocampus. The axial slices I refered to are from a different bold series of our team (you find them on open neuro https://openneuro.org/datasets/ds001419/versions/1.0.1 ).

I hope I did not miss anything and those information helps to understand what is happening. Thank you!!

Thanks. This is interesting. So your original image is in LSP orientation, but the original zooms are (2.4, 2.4, 4), so it will be (2.4, 4, 2.4) in RAS space, which seems born out.

Not really. This is an “in the interest of full disclosure” sort of statement, not a problem. Our treatment of affine matrices can be surprising to some people, so what this means is that both the qform and sform matrices were valid, but were not identical. Because the standard says that sform takes precedence we sync the qform to the sform, to accommodate tools that don’t respect the sform.

Alright, thanks. I think I’m going to need to run this to track down exactly where the flip happens. I think I agree that the outputs should be in (2.4, 4, 2.4), instead of the original (2.4, 2.4, 4) zooms. But it really might be an effect of the pitch, and the transform application step making a best guess as to which zoom set will introduce the least distortion. For such a high rotation, it might be that interpolating to (2.4mm)^3 voxels is the best approach, or moving to a boldref output. Both of these options will require additions to fMRIPrep to make happen.

Could it be the case that both q-form and s-form matrices are set and correct under the definition of NIfTI? If so, the q-form and the s-form could differ in this flip and by overwriting the q-form we are imposing the s-form (that would mean aligning to the stereotactic frame instead of the scanner’s frame). Does it make any sense to you Chris?

@anna although you can’t share T1w images at this point, it would be incredibly helpful to have a look into the first 50 timepoints of one of your bold runs. In principle, these 50 timempoints are almost useless to address any research question and identification would not be an issue for a BOLD run.

To do that:

import nibabel as nb

nii = nb.load('sub-ZZZ_task-TaskName_bold.nii.gz')
nii.__class__(nii.get_data()[..., :50], nii.affine, nii.header).to_filename('clipped_bold.nii.gz')

Thanks a lot!

I guess it’s possible if the pixdims don’t match the RSS of the sform columns that you could have a difference of axis ordering in the sform vs the qform, but that doesn’t seem to be the case here, by my reading.

@effigies @oesteban thanks for your help!

I got the data of a healthy control, who gave consent to share the data. So I uploaded T1w and the whole bold run of one condition. Still thanks for the nibabel code, I think its a more convenient way to delete the dummy scans than I did before.

The data should have the same scanning protocol. I startet now preprocessing the data without fieldmaps and freesurfer to make sure they behave the same. I will update you when fmriprep is finished.

The fmriprep code I used for all the patients is (I included fieldmaps):

nohup docker run -i --rm \

-v /usr/local/freesurfer/license.txt:/opt/freesurfer/license.txt:ro \

-v /data/anna/memory/fmriprep/data:/data:ro \

-v /data/anna/memory/fmriprep/output/out:/out \

-v /data/anna/memory/fmriprep/output/work:/scratch \

poldracklab/fmriprep:1.2.1 \

/data /out/out \

participant \

–output-space T1w template fsnative fsaverage5 \

–participant_label 36 38 39 43 53 \

–use-aroma \

–nthreads 6 \

–omp-nthreads 4 \

–write-graph \

-w /scratch &

Fmriprep is finished and preprocessed bold in both T1w and MNI look the same in this dataset as in the patients data. I added the fmriprep outputs and the reoriented image by nibabel to the link.

Hi @anna, sorry this fell off my plate. I’ll try to get to it today.

I think I tracked down the issue. I’m realizing now that perhaps the better diagnostic would have been for you to run fslreorient2std on your BOLD files before running fMRIPrep and seeing if the problem persisted. I don’t think it would have, though, and have proposed a fix.

I’ll test it locally now, and we can see what the output looks like.

1 Like

Here’s the result: RAS oriented with zooms 2.4 x 4 x 2.4

$ nib-ls sub-201/func/sub-201_task-face_space-T1w_desc-preproc_bold.nii.gz
sub-201/func/sub-201_task-face_space-T1w_desc-preproc_bold.nii.gz int16 [ 58,  46,  61, 147] 2.40x4.00x2.40x3.00

$ fslhd sub-201/func/sub-201_task-face_space-T1w_desc-preproc_bold.nii.gz  grep -A8 sform_name
sform_name     Aligned Anat
sform_code     2
sto_xyz:1      2.400000  0.000000  0.000000  -69.073967
sto_xyz:2      0.000000  4.000000  0.000000  -108.906075
sto_xyz:3      0.000000  0.000000  2.400000  -42.736328
sto_xyz:4      0.000000  0.000000  0.000000  1.000000
sform_xorient  Left-to-Right
sform_yorient  Posterior-to-Anterior
sform_zorient  Inferior-to-Superior

Thanks a lot for finding out and proposing the fix!! What is the best way to implement the fix into fmriprep? I’m currently using fmriprep 1.2.1 with the docker container.

May you have tried running fslreorient2std on your BOLD files and then rerunning fMRIPrep? I believe for the fix to have been implemented is pulling the latest fMRIPrep docker container. To preserve your version (1.2.1) it may be better to try the fslreorient2std approach before updating to see if the problem persists.

Hi @anna, if you’re okay updating to a newer version of fMRIPrep, I’m going to be pushing a (hopefully) fixed version to an experimental Docker tag within the next couple of hours. I’ll update here when it’s ready.

@anna Update: Can you try using the poldracklab/fmriprep:orientation-fix image?

2 Likes

crash-20190220-081323-root-slice_timing_correction-f26f3749-d953-4269-898b-e25edca2bb9a.txt (3.3 KB)

I started fmmriprep monday morning for some participants and it is still running, probably until friday evening, so I will try updating next week. However I ran the fslreoient2std on a single dataset and I got an fmriprep error log, because now the slice timing doesn’t match the right dimension anymore. I appended the errorlog. Is there a need for changing the dimension of the slice timing now?

Ah, good catch WRT slice timing. In any event, no. With the poldracklab/fmriprep:orientation-fix image you do not need to reorient your images prior to running fMRIPrep.

ok perfect thank you! So I will give this a try next week, when fmriprep finished running! Should the fix work well with the fieldmaps together, too? Or is there the need to change anything more for the fieldmaps?

1 Like

Yes, the fieldmaps shouldn’t have been affected by the bug; it was simply the resampling step that was affected.

1 Like

I finally tried your fix with a niworkflow repository (using the niworkflows corresponding to fmriprep 1.2.1 and changing the lines according to your fix) together with fmriprep 1.2.1 and it works!! Thanks a lot for helping and solving the problem!!

1 Like

We will be rolling out a new release with this patch soon. Thanks @anna for your patience :slight_smile:

thats great thank you!