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

Horrible BOLD brain mask: ds000109/sub-10 #1460

Closed
oesteban opened this issue Dec 21, 2018 · 15 comments
Closed

Horrible BOLD brain mask: ds000109/sub-10 #1460

oesteban opened this issue Dec 21, 2018 · 15 comments

Comments

@oesteban
Copy link
Member

Potentially an Xform issue since other runs of the same subject look good.

ds000109-horrible-bold-mask

@mslw
Copy link

mslw commented Jan 29, 2019

Can this kind of issue appear randomly? I don't know the details of how the brain mask is built, but maybe if there are some random seeds involved then it can manifest on rare occasions?

I am asking because I have noticed that a BOLD mask has gone wrong in a very similar fasion for a single subject/run (out of a dataset containing 22 subjects, 2 runs each):

run-1_rois

However, re-running this subject with both the same (1.2.3) and newer (1.2.5) version of fmriprep produced perfect masks in both cases. Likewise, I saw no problem when processing ds000109/sub-10 (checked only on 1.2.5).

Note 1: in all cases, I was running fmriprep with --fs-no-reconall.
Note 2: the brain in my picture is clipped at the top because that was the FOV during acquisition. The skull stripped T1 in MNI space looks perfect.
Note 3: when things went wrong, the run-01_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz did look like the red outline above, so it was not just a display error

@effigies
Copy link
Member

There is a little bit of randomness IIRC, but I don't know that I've seen it be more than a small shift of the border here or there. If you find a subject you can reliably reproduce the issue on, please let us know.

@markushs
Copy link
Contributor

markushs commented Mar 5, 2019

Hi! I have similar issues with some subjects in a dataset I'm working on (fmriprep 1.2.5). For a few of these subjects the issues disappeared when rerunning fmriprep, however for others not.

In the fmriprep report, the error appears already in the Susceptibility Distortion Correction output for some subjects, e.g.:

image

However, for other subjects it's only apparent in the "ROIs in BOLD space" output (similar as in the screenshots posted in previous posts). Of course, the skullstripping/mask errors messes up ICA AROMA and COMPCOR completely, and sometimes also EPI to T1 registration.

Strangely, these errors only occurs in one or a few runs per subject (all subjects have several runs associated).

As this is still an open issue, I've made small dataset (N=2) with subjects that I could reliably reproduce the issues in.
https://www.dropbox.com/sh/t5u3hza5vm0dw8b/AACAu1Bjmr-EKAA8CDnxuW8Ja?dl=0

Some details about the example data:
sub-01:
task-MCstudy_run-02 --> ROIs in BOLD space output not even produced. Formal COMPCOR ERROR
task-MCtest_run-01 --> Brainmask + ROIs completely off

sub-02:
task-MCtest_run-02 --> WM outline misplaced in SDC output; Brainmask + ROIs completely off. EPI to T1 registration fails. No errors reported by fmriprep.

Note that the study consisted of two sessions. MCstudy-run-01+02 and MCrest + structural T1w were collected during session 1. MCtest-run01-04 were collected during session 2. Fieldmaps were acquired in both sessions. As the subjects are part of a longitudinal study (in which this experiment represents one timepoint), all scans are however combined under the same session flag in the BIDS structure.

Finally: we have fMRI data from almost 600 subjects on this task (~4200 fMRI runs), and these issues were only seen in around 25 subject, so all in all fmriprep seems to be doing a remarkable job!

I'm happy to help figuring out the cause of this, but might need some input on where to look in the code.

...

Ah, yes:

image

@markushs
Copy link
Contributor

Hi! Just wondering if anyone has had a chance to look at this? As mentioned I'm happy to assist, but might need a pointer about where to look.

@effigies
Copy link
Member

So this looks like a rotated mask. Can you test on the latest release (1.3.1) and verify the issue persists? There has been a PR since 1.2.5 (nipreps/niworkflows#312) that affects BOLD orientation in some edge cases.

@oesteban
Copy link
Member Author

@markushs I'm running fmriprep 1.3.1 on your example dataset to try to narrow this down from our end as well. Hopefully, that gives us ideas on how to point you towards the right direction :)

@markushs
Copy link
Contributor

markushs commented Mar 11, 2019

@markushs I'm running fmriprep 1.3.1 on your example dataset to try to narrow this down from our end as well. Hopefully, that gives us ideas on how to point you towards the right direction :)

Thanks, that's great! I did try to run fmriprep 1.3.1 on the data on our cluster (through singularity), but it terminated immediately with somewhat similar errors as in #1534. Let me know if you need the error output to further debug that issue.

EDIT: fmriprep 1.3.1.post1 seems to solve the singularity issues for me as well, btw

@oesteban
Copy link
Member Author

@markushs I've just reproduced your issue with your data and fmriprep-1.3.1. The orientation fix did not solve this issue.

@markushs
Copy link
Contributor

@oesteban Yes, the issues were still there in most of the failing subjects when I reran using 1.3.1.post1 However, as observed by @mslw above there is some randomness to this, i.e. masks and coregs are sometimes suddenly fine after re-running (I see this both using 1.2.5 and 1.3.1).

@markushs
Copy link
Contributor

Hi @oesteban. Seems like other people are stumbling upon this issue as well. Any ideas at this point what could be the cause?
If it's ok I'll close the link to the data I provided earlier in this thread.

@markushs
Copy link
Contributor

Hi again,

I think I've maybe tracked down the problem (or at least part of it). N4BiasFieldCorrection (in bold_bold_trans_wf/bold_reference_wf/enhance_and_skullstrip_bold_wf/n4_correct) seems to be failing in some runs.

Here's ref_image_corrected.nii.gz (output of n4_correct) for a run without any issues:

image

image

And here's ref_image_corrected.nii.gz for another run from the same participant. Unsurprisingly, this one fails (confounds not produced, formal compcor errors).

image

image

The inputs to N4BiasFieldCorrection

i.e:
input_image: bold_bold_trans_wf/bold_reference_wf/gen_ref/ref_image.nii.gz
mask_image: bold_bold_trans_wf/enhance_and_skullstrip_bold_wf/check_hdr/tpl-MNI152NLin2009Asym_res-02_desc-brain_mask_trans_dil_hdr.nii.gz

look fine in both cases. At least I can't see any obvious differences in the images across the two runs and the headers seem to match. Still, rerunning the N4BiasFieldCorrection-step without a mask_image seems to fix the problem.

I confirmed that this issue is present in most of our failing subjects (typically single runs in a series of runs, as explained here previously).

Might be related to this reported issue: https://neurostars.org/t/fmriprep-n4biasfieldcorrection-fails/4043

@oesteban
Copy link
Member Author

oesteban commented May 1, 2019

Hi @markushs thanks a lot for the feedback. I hope I can have some bandwidth for this next week. I added your link to my dropbox so it should be safe to stop sharing the link.

@markushs
Copy link
Contributor

markushs commented May 2, 2019

Hi,
Another short comment on this issue. Looks like the fmriprep/nipype-implementation of N4BiasFieldCorrection in bold_bold_trans_wf/bold_reference_wf/enhance_and_skullstrip_bold_wf/n4_correct sticks with the program's defaults when it comes to bspline fitting distance. According to the ANTs N4BiasFieldCorrection-documentation the default setting is "to employ a single mesh element over the entire domain, i.e., -b [1x1x1,3]". However, one can also describe the isotropic sizing of the mesh elements as a single scalar in mm (e.g., -b [200]), which "is typically preferred" according to the documentation.

I mention this as I discovered that including -b [200] in fmripreps invocation of N4BiasFieldCorrection in n4-correct solved the current issue, that is, ref_image_corrected.nii.gz came out nice and "unbiased" also when including the mask. I also see that antsBrainExtraction.sh sets the initial bspline fitting distance to 200mm, which seems to be a parameter that has worked well with brains (and I believe was the default in N3). This discussion was informative: ANTsX/ANTs#334 (comment)

@oesteban
Copy link
Member Author

oesteban commented May 2, 2019

Hi @markushs you are absolutely right. Thank you SO VERY MUCH for your perseverance and focus into detail. Would you like to submit a PR updating the corresponding code here?

It would look like:

    n4_correct = pe.Node(ants.N4BiasFieldCorrection(
        dimension=3, copy_header=True, bspline_fitting_distance=200),
        name='n4_correct', n_procs=1)

I would do the patch myself, but I think you deserve to take all credit for this catch. For some additional guidance you can check our docs.

@oesteban
Copy link
Member Author

oesteban commented May 6, 2019

Fixed via 8f231c9

@oesteban oesteban closed this as completed May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants