Skip to content
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

Susceptibility distortion correction introduces distortion #3013

Closed
ChristianNSchmitz opened this issue May 22, 2023 · 25 comments
Closed

Susceptibility distortion correction introduces distortion #3013

ChristianNSchmitz opened this issue May 22, 2023 · 25 comments
Labels

Comments

@ChristianNSchmitz
Copy link

ChristianNSchmitz commented May 22, 2023

What happened?

Dear community,
we are using FMRIPREP for the preprocessing of task-based fMRI data. Apparently, the brain mask is not very accurate and the fMRI data is even more distorted after the susceptibility distortion correction (see image attached).
Thank you very much for your help!

What command did you use?

docker run -ti --rm  \
  -u $(id -u):$(id -g) \
  -v /data/dataPreproc/rawdata:/data:ro \
  -v /data/dataPreproc/derivatives/fmriprep-preprocessing/:/out \
  -v /data/dataPreproc/workingDirectory/:/workDir \
  -v /home/christian.schmitz/license.txt:/opt/freesurfer/license.txt \
  nipreps/fmriprep:latest /data /out  \
  participant --participant-label "${sub}" \
    --output-spaces MNI152NLin6Asym:res-2 MNI152NLin2009cAsym fsLR \
    -w /workDir \
    --return-all-components \
    --cifti-output \
    --mem 52000;

What version of fMRIPrep are you running?

23.0.2

How are you running fMRIPrep?

Docker

Is your data BIDS valid?

Yes

Are you reusing any previously computed results?

No

Please copy and paste any relevant log output.

No response

Additional information / screenshots

sub-ZI004_ses-02_task-reversal_run-01_desc-sdc_bold
Screenshot 2023-05-23 011624

@effigies
Copy link
Member

This result is with SyN-SDC?

@ChristianNSchmitz
Copy link
Author

I didn't flag SyN-SDC and used the fieldmap-based correction (default)

@effigies
Copy link
Member

I see. The --force-syn made me think you were using SyN-SDC. What type of fieldmaps do you have, what are the orientations and PhaseEncodingDirections of all of your fieldmaps and BOLD files?

@ChristianNSchmitz
Copy link
Author

ChristianNSchmitz commented May 24, 2023

Dear Chris, thanks for your help! We use a double-echo gradient echo field map sequence.
Here are the basic properties of the sequences and I have attached the *.json files:
orientations:

Fieldmap:
PhaseEncodingDirections: "i",
"ImageOrientationPatientDICOM": [0.999333, -0.0201548, 0.0304505, 0.0235506, 0.993014, -0.115626],
"ImageOrientationText": "Tra>Cor(-6.7)>Sag(1.6)"

Functional:
PhaseEncodingDirections: "j-",
"ImageOrientationPatientDICOM": [0.999333, -0.0201548, 0.0304505, 0.0235505, 0.993014, -0.115626],
"ImageOrientationText": "Tra>Cor(-6.7)>Sag(1.6)",

What might be important information: We run both a single- (Siemens sequence) and a multi-band sequence (CMRR) in the same study. Only the multi-band sequence looks off after the preprocessing.

sub-ZI004_ses-01_run-01_phasediff.txt
sub-ZI004_ses-01_task-examplerun-01_bold.txt

@ChristianNSchmitz
Copy link
Author

Brief supplement: Also shutting off the slice time correction resulted in the same distored preprocessing

@marcelzwiers
Copy link

marcelzwiers commented Jun 23, 2023

We have seen the same, however, with the latest version (23.1.#) it works well if you skull-strip / brain-extract the phasediff images before running fmriprep (use the magnitude image to compute the mask, e.g. with synthstrip)

@amirhusseinab
Copy link

Just as an additional update:
I have the same issue with both 23.0.2 and 23.1.3 versions on resting-state data applying fieldmapless method in a data without fieldmap and preprocessing with the routine pipeline with the fieldmap data available. Of note, I am running fmriprep using Singularity on a HPC.

@JohannesWiesner
Copy link

I have the same issue (probably using the same settings as @ChristianNSchmitz, I did not acquire the dataset though) with 23.1.0:

Recording 2023-07-05 at 16 56 39

@themeo
Copy link

themeo commented Jul 7, 2023

I have a very similar problem with the (almost) newest version (23.1.2; and older ones as well). I'm using the approach with fieldmaps estimated using two SBRef images with opposing orientations (AP PA). Running topup/applytopup manually on the same source images produces a correct solution.

Original image (raw functional run)
image

topup-corrected:
image

fmriprep-corrected:
image

fmriprep was run using the following command:
apptainer run --cleanenv --bind \$TMPDIR:/tmp /opt/fmriprep/23.1.2/fmriprep-23.1.2.simg /project/3011213.01/prederr/bids /project/3011213.01/prederr/bids/derivatives/fmriprep participant -w \$TMPDIR/sub-s32 --participant-label s32 --fs-license-file /opt_host/fmriprep/license.txt --mem_mb 20000 --omp-nthreads 4 --nthreads 4 --output-spaces anat func MNI152NLin2009cAsym --dummy-scans 5 --fs-subjects-dir /project/3011213.01/prederr/bids/derivatives/fastsurfer

All images (both fieldmaps and BOLD file) had LAS orientation.
AP fieldmap and BOLD had "PhaseEncodingDirection": "j-"
PA fieldmap had "PhaseEncodingDirection": "j"

Like in @ChristianNSchmitz 's case, the BOLD was collected using a CMRR multiband sequence.

@effigies
Copy link
Member

From discussion with @oesteban, the issue here is not the distortion correction but the Jacobian attenuation. These stretches outside the brain also happen with TOPUP (in the most recent post you can clearly see the shape of these stretches in both TOPUP and fMRIPrep), but are scaled by the Jacobian of the B-spline field.

Tracking this feature in nipreps/sdcflows#382.

@tiborst
Copy link

tiborst commented Jul 19, 2023

I have encountered a similar problem in my dataset and I was wondering whether it might be possible to introduce already distortion corrected images into the fmriprep pipeline and use the tag --ignore fieldmap?
Running fieldmap correction / unwarping in FSL did not introduce similar artefacts.

Would this be a feasible approach?

@amirhusseinab
Copy link

@tiborst I am now going for the same solution. There is another ongoing discussion here, which you may be also interested in.

@andreifoldes
Copy link

We have seen the same, however, with the latest version (23.1.#) it works well if you skull-strip / brain-extract the phasediff images before running fmriprep (use the magnitude image to compute the mask, e.g. with synthstrip)

@marcelzwiers could you please further details how you do the skullstripping, I'd like to give this a try.

@marcelzwiers
Copy link

marcelzwiers commented Sep 11, 2023

We have seen the same, however, with the latest version (23.1.#) it works well if you skull-strip / brain-extract the phasediff images before running fmriprep (use the magnitude image to compute the mask, e.g. with synthstrip)

@marcelzwiers could you please further details how you do the skullstripping, I'd like to give this a try.

Sure, the basic idea is to compute the mask on the fieldmap magnitude image and apply that mask to the phasediff images in the fieldmap folder (overwriting the original phasediff data, so you may want to make a backup). In bidscoin this can be done with a single command, e.g.:

skullstrip myproject/bids fmap/*_magnitude1* -m fmap/*_phasediff -o extra_data fmap

This save a masked magnitude1 image in the extra_data subfolder and a masked phasediff image in the fmap folder (if you don't have/want extra_data, then delete these folders or add extra_data/ to your .bidsignore file). Then run fmriprep normally (it will use the masked phasediff data)
See here for more info:
https://bidscoin.readthedocs.io/en/latest/bidsapps.html#skull-stripping

@effigies
Copy link
Member

@themeo Would you mind sharing the exact topup/applytopup commands you're using? It would be helpful to have a ground truth for comparing our fixes.

@themeo
Copy link

themeo commented Sep 28, 2023

Sure! Nothing fancy here, though:

fslmerge -t AP_PA_b0.nii.gz sub-s21_acq-ROPESBRef_dir-AP_run-1_epi.nii.gz sub-s21_acq-ROPESBRef_dir-PA_run-1_epi.nii.gz

topup --imain=AP_PA_b0.nii.gz --datain=acqparams.txt --config=b02b0.cnf --out=topup_res --iout=AP_PA_b0_unwarped.nii.gz --fout=myfieldmap.nii.gz

applytopup --imain=sub-s21_task-Main_dir-AP_run-1_bold.nii.gz --inindex=1 --method=jac --datain=acqparams.txt --topup=topup_res --out=sub-s21_task-Main_dir-AP_run-1_desc-unwarped_bold.nii.gz

I'd be happy to share specific data files if needed.

@effigies
Copy link
Member

effigies commented Oct 1, 2023

Thank you very much. That was helpful for debugging. I have a working fix in nipreps/sdcflows#391.

@amirhusseinab
Copy link

Thanks Chris! It solved my long-standing issue with SDC, but I encountered some problems running it. I tried to manually edit transform.py based on your solution with singularity --sandbox and rebuilding the singularity image. I did it on v23.1.4 and "fmriprep:next" versions.

  • on v23.1.4. the analysis stopped, with an error in the node "Node Name: fmriprep_23_1_wf.single_subject_{subid}_wf.func_preproc_ses_001_task_rest_dir_RL_wf.unwarp_wf.resample" with " AttributeError: 'B0FieldTransform' object has no attribute 'xfm'"
  • on the fmriprep:next it ran smoothly, with the SDC applied (Thanks!), but no files in other spaces (T1w, fsLR, MNI*) are generated in the func folder, with no errors.

I know it is still in the development phase but I wondered if I could try to have things run since I'm facing a deadline ahead.

@effigies
Copy link
Member

effigies commented Oct 4, 2023

Let me see if I can backport these fixes without too much difficulty. I'm not sure how much the current fixes depend on larger changes we've made.

@effigies
Copy link
Member

effigies commented Oct 4, 2023

Please see nipreps/sdcflows#397 and nipreps/sdcflows#398. Tests from users experiencing the problems with blip-up/blip-down (nipreps/sdcflows#397) and phasediff/fieldmaps (nipreps/sdcflows#398) would be greatly appreciated. Instructions for testing with fmriprep-docker are in each PRs initial post.

@jameswyngaarden
Copy link

Hi all, thank you for all of the helpful information in this thread. Following up here from #3093--it looks like the fix in nipreps/sdcflows#391 addresses the issue of abnormal distortions around the outlines of the image. However, we are also seeing strange distortions inside the corrected images for multiband=6, multi-echo=4 images, even when distortions around the outlines have been avoided:

Corrected:
Screenshot 2023-10-30 at 9 00 24 AM

Distorted:
Screenshot 2023-10-30 at 9 00 51 AM

In this case, using fieldmap-free distortion correction in fmriprep 23.1.4 similarly resolves the issues around the outlines of the image, but we still see this abnormal pattern inside. I wanted to follow up to see if others have thoughts about addressing this pattern? Thank you!

	echo singularity run --cleanenv \
	-B ${TEMPLATEFLOW_DIR}:/opt/templateflow \
	-B ${MPLCONFIGDIR_DIR}:/opt/mplconfigdir \
	-B $maindir:/base \
	-B ~/work/tools/licenses:/opts \
	-B $scratchdir:/scratch \
	~/work/tools/fmriprep-23.1.4.simg \
	/base/bids /base/derivatives/fmriprep-syn \
	participant --participant_label $sub \
	--stop-on-first-crash \
	--me-output-echos \
	--ignore fieldmaps \
	--use-syn-sdc \
	--cifti-output 91k \
	--output-spaces fsLR fsaverage MNI152NLin6Asym \
	--bids-filter-file /base/code/fmriprep_config.json \
	--fs-license-file /opts/fs_license.txt -w /scratch >> $logdir/cmd_fmriprep_${PBS_JOBID}.txt

@manzouri
Copy link

manzouri commented Nov 7, 2023

Hi @effigies , I wonder if the fix for this will be implemented in next release before end of the year?

@effigies
Copy link
Member

This fix is available in 23.2.0a1. Please test and let us know how it goes!

@github-project-automation github-project-automation bot moved this from In Progress to Done in fMRIPrep 23.2alpha Nov 21, 2023
@jameswyngaarden
Copy link

Hi all, wanted to follow up now that we have tested the latest pre-release. In the previous version of fmriprep, fieldmap-free distortion correction looked pretty good for most sequences, but we have noticed now that use of the synthetic fieldmap in the latest version looks a bit odd. Here are screenshots from the same subject & sequence I posted about in #3093. I just wanted to flag this and note that we’re seeing this difference:
image
image (1)

@effigies
Copy link
Member

Please follow-up in #3158.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

10 participants