I am trying to extract values from a 3D niimg object (a beta map) according to an atlas.
I succeeded in extracting values with spheres (NiftiSpheresMasker) but with NiftiLabelsMasker or NiftiMapsMasker, I get an error message :
Input data has incompatible dimensionality: Expected dimension is 4D and you provided a 3D image
from the error message it sounds like atlas_filename contains a 3d image (with integers indicating regions?) so NiftiLabelsMasker should work. If it doesn’t, could you share the atlas and beta map?
thanks. indeed it seems the maskers cannot handle a single 3d image, which is indeed a bit surprising and not the documented behaviour. I’ll open an issue but in the meanwhile you can use masker.fit_transform([fmri_filenames])[0]
(ie pass a list containing one filename instead of the filename directly)
Thanks a lot for your help and your time but the error message remains the same
I will try to concatenate several subjects (or several times the same) beta maps in order to get a fake 4D niimg object as implicitly required.
What is disturbing is that it works (or seems to work) with NiftiSpheresMasker for 3D niimg object.
For replication purpose, I just modified a bit the nilearn example provided
from nilearn import datasets, image
dataset = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-2mm')
atlas_filename = dataset.maps
labels = dataset.labels
print('Atlas ROIs are located in nifti image (4D) at: %s' %
atlas_filename) # 4D data
# One subject of brain development fmri data
data = datasets.fetch_development_fmri(n_subjects=1)
###### code modification ###########
fmri_filenames = image.index_img(image.load_img(data.func[0]),0)
###### end of code modification ######
from nilearn.input_data import NiftiLabelsMasker
masker = NiftiLabelsMasker(labels_img=atlas_filename, standardize=True,
memory='nilearn_cache', verbose=5)
# Here we go from nifti files to the signal time series in a numpy
# array. Note how we give confounds to be regressed out during signal
# extraction
time_series = masker.fit_transform(fmri_filenames, confounds=data.confounds)
And using concat does not work with my beta maps but works with the example dataset reduced to one 3D niimg object.
sorry I’m not sure I understand; in both examples (with development dataset and with beta_0001.nii) replacing fmri_filenames with [fmri_filenames] worked for me.
you still get the same error when doing that?