How can I improve the brain mask generated by nilearn's compute_epi_mask?

The brain mask generated by fMRIprep for my EPI is not bad but also not great (i.e. check out the back of the brain on the sagittal section, check out the dorsal part of the coronal section).

So I used nilearn’s compute_epi function. Interestingly, this function seems to hug the anatomy close for a better fit along the border of the cortex and fixes the aforementioned problems. However, it has the obvious issue of failing on the temporal lobes/ventral part. I tried changing the lower_cutoff value up and down, and it made zero difference. upper_cutoff also didn’t change anything.

Changing ‘opening’ did have some interesting effects, but nothing good overall:
opening = 1

opening = False

opening greater than 2 just made the problem worse.

any advice? is there anything i can tweak to get a good mask from this? am i overreacting about the fmriprep mask?

thank you :slight_smile:

1 Like

If both are too conservative, but in different ways, you could try taking the union of the masks.

1 Like

Thanks this is probably the best call. fmriprep mask is too liberal in some places too conservative in others, but overall better too liberal than too conservative imo.

Another possibility is to smooth a bit your image before maks computation. It may help.
I think that the method has been designed for data with less strong bias field.


What we tend to do in our lab is to use the mask calculated on the anatomical image from the union of the GM, WM and CSF probseg masks and to resample it to the bold resolution.

Its not nilearn but you could use AFNI automask AFNI program: 3dAutomask
I like invoking it from python by calling it using the “subprocess” package