Brain mask and brain tissue segmentation cutting off cerebellum in fMRIprep

Cerebellum is cut off across multiple participants. This is not happening for most participants, but around 10 out of 200. I have tried rerunning after deleting working directory files and all other related files. I am not getting any error messages associated with this issue. Thank you in advance for any help you can provide.

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

singularity run --bind /isilon/datalake/ptcrc_meadelab/Neuroimaging/Software/fmriprep_neuroimgapp01 --bind /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_fmriprep_v23 --bind /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_BIDS_v23/baseline --bind /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/fmriprep_workingdir_v23 --cleanenv /isilon/datalake/ptcrc_meadelab/Neuroimaging/Software/fmriprep_neuroimgapp01/fmriprep23.2.0.simg  /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_BIDS_v23/baseline /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_fmriprep_v23 participant --participant-label 3024 3219 -w /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/fmriprep_workingdir_v23 --skip_bids_validation --fs-license-file /isilon/datalake/ptcrc_meadelab/Neuroimaging/Software/license.txt --use-syn-sdc --output-spaces MNI152NLin6Asym

Version:

Version 23.2.0

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

Singularity

Data formatted according to a validatable standard? Please provide the output of the validator:

PASTE VALIDATOR OUTPUT HERE

Relevant log outputs (up to 20 lines):

PASTE LOG OUTPUT HERE

Screenshots / relevant information:


Hi @rbell and welcome to NeuroStars!

What kind of T1w image are you using? 7T data? You may want to provide your own brain mask as it looks like the brain mask calculated by fmriprep on these datasets is cutting out the cerebellum. You could try to give your own skull stripped image and use --skull-strip-t1w skip in your fmriprep call. I am not entirely sure that this will improve the anatomical segmentation.

Otherwise, you could follow what is said in this recent thread: fMRIPrep Normalization failed in a problematic subject

Thank you, @jsein! I tried implementing using my own brain mask using SPM segmentation and combining the GM and WM images. I am now getting this error message:


Node: fmriprep_23_2_wf.sub_3024_wf.anat_fit_wf.apply_mask
Working directory: /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/fmriprep_workingdir_v23/fmriprep_23_2_wf/sub_3024_wf/anat_fit_wf/apply_mask

Node inputs:

in_file = <undefined>
in_mask = /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_BIDS_v23/baseline/mymask/sub-3024/anat/sub-3024_desc-brain_mask.nii.gz
threshold = 0.5

Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node apply_mask.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/niworkflows/interfaces/nibabel.py", line 75, in _run_interface
	    raise ValueError("Image and mask affines are not similar enough.")
	ValueError: Image and mask affines are not similar enough.

Any ideas on what might be going on? I do see that the in_file label is “undefined”. Might that be the issue?

Hi @rbell , the message “Image and mask affines are not similar enough” makes me think that you would need to resample your mask into your input T1w space to be sure that the mask and the input T1w have the same dimensions and orientation. You should verify also that they do overlap well!

I resampled the mask to the input T1w space and confirmed the overlap looked good but still getting the same error message. Any other thoughts?

Could you show the affine matrices of the two images: the brain mask and the input T1w images?

Not seeing any difference between the two.

image

image

Thank you for this information. This is indeed always a bit tricky.
This is the qform affine. You may want to check also the storm affine, especially when you use SPM that store transformation in one of the affine matrice.

When looking at the error message, you can see that it is coming from this piece of code:

 if not np.allclose(img.affine, msknii.affine):
            raise ValueError("Image and mask affines are not similar enough.")

You could just run these lines with your two images to see if that gives the same error message. If not, this means that you are not looking at the same images as fmriprep when this check occurs.

Really appreciate your help with this. Storm affines are also the same. My question is whether it is failing on the submitted T1w image or the noise corrected T1?

This is the apply mask script:

Node: sub_3024_wf (anat_fit_wf (apply_mask (nibabel)

Hierarchy : fmriprep_23_2_wf.sub_3024_wf.anat_fit_wf.apply_mask
Exec ID : apply_mask

Original Inputs

  • in_file : /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/fmriprep_workingdir_v23/fmriprep_23_2_wf/sub_3024_wf/anat_fit_wf/anat_validate/sub-3024_ses-baseline_T1w_noise_corrected_ras_valid.nii.gz
  • in_mask : /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_BIDS_v23/baseline/mymask/sub-3024/anat/sub-3024_desc-brain_mask.nii.gz
  • threshold : 0.5

I see that the “in_file” is the noise corrected T1w. When I view this image it is in a different orientation (neurological vs. radiological) relative to the mask. Could this be the issue?

As an update, if I register to the T1w noise correct file listed above I no longer receive the error message regarding image and mask affines not being similar enough. However, I do get the following error message now:

Cmdline:
antsApplyTransforms --default-value 0 --float 0 --input /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_BIDS_v23/baseline/mymask/sub-3024/anat/sub-3024_ses-baseline_desc-brain_mask.nii.gz --interpolation MultiLabel --output sub-3024_ses-baseline_desc-brain_mask_trans.nii.gz --reference-image /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/fmriprep_workingdir_v23/fmriprep_23_2_wf/sub_3024_wf/syn_preprocessing_auto_00001/sampling_ref/clipped_reference.nii.gz --transform [ /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/fmriprep_workingdir_v23/fmriprep_23_2_wf/sub_3024_wf/syn_preprocessing_auto_00001/epi2anat/transform0GenericAffine.mat, 1 ]
Stdout:

Stderr:
Exception caught during reference file reading

itk::ImageFileReaderException (0x5640d0c4c6a0)
Location: "unknown" 
File: /opt/conda/envs/fmriprep/include/ITK-5.3/itkImageFileReader.hxx
Line: 132
Description:  Could not create IO object for reading file /isilon/datalake/ptcrc_meadelab/CONNECT/MRI/data_processed/BIDS/data_BIDS_v23/baseline/mymask/sub-3024/anat/sub-3024_ses-baseline_desc-brain_mask.nii.gz
  Tried to create one of the following:
    BMPImageIO
    BioRadImageIO
    Bruker2dseqImageIO
    GDCMImageIO
    GE4ImageIO
    GE5ImageIO
    GiplImageIO
    HDF5ImageIO
    JPEGImageIO
    JPEG2000ImageIO
    LSMImageIO
    MGHImageIO
    MINCImageIO
    MRCImageIO
    MetaImageIO
    NiftiImageIO
    NrrdImageIO
    PNGImageIO
    StimulateImageIO
    TIFFImageIO
    VTKImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.