We’re encountering a persistent issue with mask generation during fMRIPrep processing, which results in the cerebellum being cut off and a stretched T1w-to-MNI normalization (see video here). After troubleshooting, we identified that the problem might be related to ANTs. We attempted brain extraction using optiBET, which successfully retained the cerebellum (see video here).
Following this, we tried providing the skull-stripped T1 image from optiBET directly to fMRIPrep as the input file, hoping it would simplify segmentation. However, the problem persisted, with the cerebellum still being cut off in the generated masks.
Our next step was to use the output masks from optiBET in fMRIPrep via the --derivatives flag. Unfortunately, we’re constrained to fMRIPrep version 20.0.0 on our cluster, and it seems this flag wasn’t introduced until version 22.3.0.
If anyone has suggestions or alternative approaches, we would greatly appreciate the help—we’ve been stuck on this for weeks!
Command used (and if a helper script was used, a link to the helper script or the command generated):
I run the following in the terminal which calls on the scripts linked below: python iteachmri.py --json data_iteachmri.json --steps fmriprep --sub {X}
The code that executes the command (found in the helper script) is as follows:
Thanks for your quick response ! Absolutely nothing – I just saw a caveat in the fMRIPrep documentation that the --derivatives flag was experimental and so wasn’t sure if there was a different solution that I was missing. Sounds like using another container version is the best course of action?
Thank you for your response! We’ve since updated the container version and are re-running the pipeline with the --derivatives flag. However, we’ve encountered a few challenges and have some questions:
Mask and Image Orientation Mismatch: When substituting the initial fMRIPrep brain mask with the optiBET brain mask, fMRIPrep throws an error indicating that the mask and image are not the same size. Upon inspection, we found that the raw T1 has dimensions of 256 x 256 x 176, the fMRIPrep brain mask has dimensions of 176 x 256 x 256, and the optiBET brain mask matches the raw T1 orientation (256 x 256 x 176). This suggests that fMRIPrep reorients the T1 internally.
Is it safe to reorient the optiBET brain mask to match the fMRIPrep mask dimensions (176 x 256 x 256) and proceed? If so, what would be the best way to handle this reorientation to avoid introducing any errors or artifacts?
Pipeline Behavior with --derivatives Flag: When using the --derivatives flag, we’re unclear about where fMRIPrep picks up in the pipeline and how it handles new inputs. For instance:
If we provide a new mask (e.g., from optiBET), will fMRIPrep redo registrations using the updated mask, or will it continue from the outputs of the prior run, skipping steps like registration entirely?
Specifically, how does the --derivatives flag influence the outputs when re-running the pipeline with new masks or preprocessed files? Understanding this is critical for ensuring that the pipeline is producing outputs based on the updated inputs.
Our concern is that reorienting the optiBET brain mask might just be a temporary fix if the underlying issue isn’t addressed. We want to confirm that this approach will lead to improved masks and registrations in the final outputs.
Any clarification or guidance on these points would be greatly appreciated! We’re eager to resolve this issue and move forward.
I can’t exactly say without knowing more about the error. It would help to see the full error traceback, then you can use the information in the traceback to see where the reoriented file lives in the working directory. Then you can visualize the two images to see how the images are reoriented.
I am not sure I understand exactly what you are asking. By prior run, are you referring to an earlier fmriprep run, or the step used to create the additional derivatives?
How it influences results would be based on what derivatives you pass in. I am not sure I can provide a general answer for this.
What underlying issue are you referring to?
If you want to avoid using --derivatives flag, you could try putting the skull stripped T1w in the BIDS directory, with a distinctive acq-<> or rec-<> label, use a BIDS filter file to use the skull stripped T1w while ignoring the original, and keep the skip skull strip flag on.
Understood – we’ll look into that and see if we can locate the workdir reoriented file.
The former – so the pipeline that we have been running is as follows:
Run optiBET and save outputs somewhere outside derivatives (will get mask and skull-stripped brain for each subject)
Swap optiBET skull stripped brain for raw T1 for every subject
fMRIPrep Stage 1: run with --level minimal flag and no --derivatives flag (results will be saved in bids/derivatives/derivatives_min)
In bids/derivatives/derivatives_min/sub-[X]/ses-[X]/anat/rename fMRIPrep brain mask so it doesn’t get used in next step: e.g., mv sub-35_ses-day2_desc-brain_mask.nii.gz sub-35_ses-day2_desc-brain_mask_fmriprep.nii.gz
Copy optiBET brain mask into bids/derivatives/derivatives_min/sub-35/ses-day2/anat/ and rename it to the name that fMRIPrep is expecting (e.g., sub-35_ses-day2_desc-brain_mask.nii.gz) - in other words, swap out fMRIPrep mask with optiBET mask
Re-orient optiBET brain mask(???) But this is also weird b/c fMRIPrep is able to start with raw T1 in same orientation as optibet mask, suggesting that --derivatives flag is starting too far down the pipeline (i.e., not with raw T1, but with data that were reoriented in Stage 1)
fMRIPrep Stage 2: run “full” derivatives with swapped out mask using --derivatives flag that points to derivatives_min directory and outDir = derivatives/derivatives_full
Can you describe how it went wrong? I know you said that you tried putting the skull stripped T1w as the raw with version 20.0.0 with the skip skull strip flag. Given that it looks like that flag was introduced after 20.0.0 (looks like it was 20.1.0rc1 Merge pull request #2039 from oesteban/enh/skip-anat-brain-extraction · nipreps/fmriprep@0482c23 · GitHub), that’s probably why it didn’t work. But I don’t know what precisely you’ve tried with the most recent version, which makes it difficult for me to provide specific support.
One issue I see is that the final anatomical derivative for the T1 isn’t just skull stripped, but entirely preprocessed (i.e. with additional steps like intensity normalization). If you want the have fmriprep use it as a precomputed derivative, it should be entirely preprocessed in RAS space and named accordingly, like the usual fmriprep anatomical output.
We’re pretty confident that the skull strip flag isn’t the issue (or rather, the solution) because when we tried running fMRIPrep with --level minimal and the skull-stripped T1 (from OptiBET), the brain mask still cut off much of the cerebellum as before. We did this with both version 20.0.0 and with the more recent version 22.3.0. We’ve been scratching our heads trying to figure out why this might be…
Hmm I’m not quite sure what you mean by “final anatomical derivative for the T1”. My understanding based on the 7 steps outlined above is that we are running only the OptiBET brain extraction and manually swapping the non-skull-stripped T1 for the skull-stripped T1. Unless I’m mistaken, OptiBET shouldn’t run any other steps on the raw T1 file (i.e., intensity normalization). Am I missing something here?
I’m also still unclear on where the --derivatives run (Stage 2, Step 7) will pick up after we’ve done an initial run through with the --level minimal flag.
Apologies for the confusion and I appreciate your support (especially during the holidays)!
Can you please explicilty clarify whether you used the skull-strip flag with this? Perhaps share the command?
May you please use the most recent version?
By final derivative I mean the desc-preproc_T1w.nii.gz. What I am saying is that if you want to pass in a skull stripped image as a derivative, then it should be in the form of a final fmriprep anatomical output (like you would find in the anatomical output folder). That is, not only skull stripped, but also with all other preprocessing applied to it.
Is it possible for you to share a subject’s worth of data?