I am using Parcellations from nilearn.regions to do a Ward clustering on fMRI data. However, creating masks from nilearn.masking gives me a numpy array, which creates a problem, since Parcellations objects can’t take in numpy arrays.
How can I apply a mask over my fmri scans so that I can use the ward clustering on them? Thanks.
Ahoi hoi @Pranay1717,
as far as I can tell, you would need to compute the mask based on to your image(s), defining only voxels/regions you’re interested in and afterwards apply Ward clustering to the images indicating the computed mask as such within the Parcellation definition. A nice example wrt extracting/masking is provided in the nilearn docs, but in brief this is how it could look like:
# import necessary functions
from nilearn.image.image import mean_img
from nilearn.masking import compute_epi_mask
from nilearn.regions import Parcellations
#fetch example data
haxby_dataset = datasets.fetch_haxby()
func_filename = haxby_dataset.func[0]
# compute mask
mask_img = compute_epi_mask(func_filename)
# set up ward parcellation
ward = Parcellations(method='ward', n_parcels=1000,
standardize=False, smoothing_fwhm=2.,
memory='nilearn_cache', memory_level=1,
mask=mask_img, verbose=1)
# compute ward parcellation from data using computed mask
ward.fit(func_filename)
# check computed parcellation by visualizing it as overlay on the mean functional image
from nilearn import plotting
ward_plot = plotting.plot_roi(ward_labels_img, title="Ward parcellation", display_mode='xz',
bg_img=mean_image(functional_image)
HTH, cheers, Peer
1 Like
ah I didn’t know that there was a parameter in the parcellations object for masks
+1 thanks that was really helpful