Error when applying functional mask to smoothed ICA-AROMA output

I am trying to apply the brain mask generated by fmriprep to the smoothed preprocessed output of ICA-AROMA. However, the following error is thrown

WARNING:: Inconsistent orientations for individual images in pipeline!
          Will use voxel-based orientation which is probably incorrect - *PLEASE CHECK*!

Image Exception : #3 :: Attempted to multiply images of different sizes
terminate called after throwing an instance of 'std::runtime_error'
  what():  Attempted to multiply images of different sizes
2_apply-mask.bash: line 22: 115991 Aborted                 fslmaths $file -mas $intMask $intOutput

When checking the file info (fslinfo) the following is this:

smoothed ICA-AROMA file

data_type	FLOAT32
dim1		91
dim2		109
dim3		91
dim4		564
datatype	16
pixdim1		2.000000
pixdim2		2.000000
pixdim3		2.000000
pixdim4		2.066000
cal_max		31407.859375
cal_min		-2726.825439
file_type	NIFTI-1+

functional mask from fmriprep

data_type	UINT8
dim1		65
dim2		77
dim3		60
dim4		1
datatype	2
pixdim1		3.000000
pixdim2		3.000000
pixdim3		3.300000
pixdim4		0.000000
cal_max		0.000000
cal_min		0.000000
file_type	NIFTI-1+

I had thought to resample using flirt but the centering still seems off, as it is more than just the voxel dimensions that differ. Has anyone encountered a solution for this?

The output of Aroma is in the MNI152NLin6Asym space. Do you use use the masks calculated in the same space?

Ah… no. I think the BOLD timeseries is resampled in the MNI152NLin2009cAsym space. So, I guess the mask is coming from a different MNI space. How could I align the two?

To know in which space the files are processed into, you need to look at the tag _space- in the file name.

Check if by any chance fmriprep did not already produced brain masks files in the MNI152NLin6Asym space. If not, I see two possibilities for you:
1/ Re-run fmriprep by adding MNI152NLin6Asym after --output-spaces to be sure that fmriprep produces all the processed output in that space.
2/ You may combine the two transform: sub-XX_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5 and sub-XX_from-T1w_to-MNI152NLin6Asym_mode-image_xfm.h5 (with antsApplyTransforms) to convert your brain mask file from MNI152NLin2009cAsym space to MNI152NLin6Asym (using NearestNeighboras interpolation method).

Ah okay. Thank you for the suggestions! I am trying them both in parallel (as fmriprep takes so long to run), but I am having issues with antsApplyTransforms. When I try to run ants I get the following error…

command: sudo ant
error:

Buildfile: build.xml does not exist!
Build failed

I have tried running from the specific directory and from root (as it was installed using sudo apt-get), but both throw this error. Have you encountered this issue?

I also reran on subject in fmriprep specifying the MNI152NLin6Asym as the --output-space. However, the files still seem to have different dimensions even though they are registered in the same space?

smoothed aroma in MNI152NLin6Asym space:

data_type	FLOAT32
dim1		91
dim2		109
dim3		91
dim4		564
datatype	16
pixdim1		2.000000
pixdim2		2.000000
pixdim3		2.000000
pixdim4		2.066000
cal_max		31481.035156
cal_min		-2600.937744
file_type	NIFTI-1+

mask in MNI152NLin6Asym space:

data_type	UINT8
dim1		61
dim2		73
dim3		56
dim4		1
datatype	2
pixdim1		3.000000
pixdim2		3.000000
pixdim3		3.300000
pixdim4		0.000000
cal_max		0.000000
cal_min		0.000000
file_type	NIFTI-1+

When I try to apply the mask to the preprocessed image I get this error:

WARNING:: Inconsistent orientations for individual images in pipeline!
          Will use voxel-based orientation which is probably incorrect - *PLEASE CHECK*!

Image Exception : #3 :: Attempted to multiply images of different sizes
terminate called after throwing an instance of 'std::runtime_error'
  what():  Attempted to multiply images of different sizes
2_apply-mask.bash: line 30: 193081 Aborted                 fslmaths $file -mas $intMask $intOutput

Thank you for those details. It looks like AROMA is producing outputs in space: MNI152NLin6Asym upsampled to 2mm resolution (see discussion here) while the command --output-spaces MNI152NLin6Asym produces outputs in native resolution (which looks like it is 3x3x3.3mm in your case).

Again, I see two choices:
1/ either you re-run again fmriprep ( if you re-use the working directory (option -w) not everything will be re-run again) with --output-spaces MNI152NLin6Asym:res-2 (more details on this option here)
2/ you can resample the bold mask in the 2mm resolution. Several possibilities:

  • using FSLeyes: load the two images, the mask and the smoothed aroma image, then highlight the mask image and click on: Tools > Resample image and on the top right select the smoothed aroma image, choosing “nearest neighbor” for interpolation: voilà!
  • with flirt: flirt -in brain mask_space-MNI152NLin6Asym_in_native resolution -ref smoothed_aroma_space-MNI152NLin6Asym_in_2mm_resolution -out brain mask_space-MNI152NLin6Asym_in_2mm resolution -interp nearestneighbour -applyxfm