I have a dataset with 33 participants and 3 runs of the same task. I preprocessed the dataset with fmriprep and I want to analyze it with nilearn. However, while doinf the analysis I’ve discovered that masks and preprocessed bold for some images have affines different from the rest of the dataset, and because of that I can’t run GLM analysis via nilearn.
Do you know why this might be the issue and what can be done about it?
I checked raw nifti, and the sizes of the images are the same, but the affines are different.
So did I understand correctly: the only solution is to rerun fmriprep with this new output space specification?
I’m sorry, I didn’t finish writing this last week…
If you look at the pixdim field (you can use fslhd or similar), I expect you’ll see something like the following rows (where TR is your repetition time):
For such a small difference (0.0001mm), you can probably just overwrite the header. An example:
import numpy as np
import nibabel as nb
good_img = nb.load(fname1) # Use this image's affine
img_to_update = nb.load(fname2) # Use this image's data
new_img = nb.Nifti1Image(
np.asanyarray(img_to_update.dataobj),
affine=good_img.affine,
header=img_to_update.header) # Keep everything in the header but the affine
new_img.to_filename(fname2)
Yes, you can do that, though I have seen some weird results when resampling images with such small differences in voxel sizes. I would make sure to have a close look at the results.
I’m encountering a similar issue. My functional images have voxel dimensions of 2.973 x 2.973 x 3 mm. Is it suitable to use ‘res-2’? I’m inclined to find a template with a resolution closer to the native space (e.g., 3x3x3). However, I couldn’t locate an option for the default template MNI152NLin2009cAsym with a voxel size of 3x3x3. Could you suggest which template might be appropriate? I stumbled upon ‘tpl-MNI152NLin2009cAsym_res-03_atlas-DiFuMo’ in TemplateFlow, but I’m unsure if this is the right choice and how to specify the use of this template.