Mask computation and quality check : fMRI images are in MNI template but NiftiMasker() seems to leave out data while computing mask

Summary of what happened:

I have some preprocessed fMRI timeseries that are aligned in MNI space. I ultimately want to extract timeseries from regions based on an atlas (using MultiNiftiMapsMasker), but the generate_report() function does not seem to work for me (edit : see the reply below). In the meantime I just want to know that I extract the data correctly before further analyses. Hence, I use the NiftiMasker() and its report. As images show below, when plotting mean image onto the MNI template, it seems aligned, but when the computed mask using NiftiMasker with MNI template seems too small for the data. I dot not have access to a mask from the preprocessing output.

Command used (and if a helper script was used, a link to the helper script or the command generated):

from nilearn import image
func = nib.load(func_path)
mean_img = image.mean_img(func)
print(mean_img.shape)
plotting.view_img(mean_img, bg_img='MNI152', title='mean img with MNI BG').save_as_html('mean_img.html')
plotting.plot_img(mean_img, title = 'mean_img',)

voxel_masker = NiftiMasker(
    mask_strategy = 'whole-brain-template',
    smoothing_fwhm = 6,
    verbose=5,
)
voxel_masker.fit(func)
voxel_masker.generate_report().save_as_html('masker_report.html')

Version:

Nilearn version: 0.10.2

Environment (Docker, Singularity / Apptainer, custom installation):

ran on venv

Relevant log outputs (up to 20 lines):

(91, 109, 91) # shape mean_img

Screenshots / relevant information:

image


In the second image, we see that the image is normalized in MNI space, but the signal slightly look out of the template in the frontal areas. I wonder if there are ways to ‘trust’ that this signal could be remove (hence the masker report would show accurate information ?), assuming that the images are correctly registered in MNI space.

I tried many alternatives, like different parameters for mask_strategy in NiftiMasker(). I also tried to compute a binary mask from the MNI template (from nilearn.datasets import load_mni152_brain_mask), and to apply a threshold on my images.

More globally, I am really looking for ways to efficiently look at the data to make sure I can proceed with subsequent statistical analyses. Corollary questions (that I could address in another post if more relevant) would be :

  1. Is it better to compute the masker from all my timeseries from all participant at one (by concatenating all participants’ 4D images)?
  2. Are there other ‘diagnostic’ for data processing other than masker_reports and plotting images (how to proceed when having lots of data from different subjects?)

Thank you very much for any input!
Best,

Dylan


Just checked and the NiftiMapsMasker does have generate_report method.

Sorry, I meant MultiNiftiMapsMasker. It does have it in the documentation, but I get :
nilearn._utils.exceptions.DimensionError: Input data has incompatible dimensionality: Expected dimension is 4D and you provided a list of 4D images (5D). See https://nilearn.github.io/stable/manipulating_images/input_output.html

I thought the purpose of Multi*Maskers is to handle multiple subjects, hence 5D images. Would it be valid to just concatenate all the 4D images from all the subjects to pass it to the .fit() step to overcome this dimensionality error?

Thanks,
Dylan

But you should rather throw into it images subject by subject — there is no reason to throw them together, it just makes things heavier. Then you would ahve 4D data right ?
You should also use the same MNI mask for all subjects. If you use a proper MNI brain or grey matter mask, nothing will remain out of the template brain.
HTH,
Bertrand