I have about 20 subjects with and without ASD fetch from ABIDE using nilearn. Using fit_transform of NiftiMasker object, we mask the images and then use FastICA to get the independent components. Trying to invert the masking procedure using inverse_transform throws the error ‘X must be of shape…’
Here is the code:
pitt_typical_ds=fetch_abide_pcp(SUB_ID=[50030, 50031])
from nilearn.input_data import NiftiMasker
masker = NiftiMasker(smoothing_fwhm=8, memory='nilearn_cache', memory_level=1, mask_strategy='epi',
standardize=True)
typical_timeseries=[]
for typical in pitt_typical_ds.func_preproc:
timeseries=masker.fit_transform(typical)
typical_timeseries.append(timeseries)
ica=FastICA(n_components=10, random_state=42)
for typical in typical_timeseries:
components_masked=ica.fit_transform(typical.T).T
# Normalize estimated components, for thresholding to make sense
components_masked -= components_masked.mean(axis=0)
components_masked /= components_masked.std(axis=0)
# Threshold
import numpy as np
components_masked[np.abs(components_masked) < .8] = 0
# Now invert the masking operation, going back to a full 3D
# representation
component_img = masker.inverse_transform(components_masked)