Visualize single regions from the aal atlas in nilearn

I have a basic question, but I am really stuck.

How can I visualize a single region from the aal atlas in nilearn? Now, I can only plot the whole atlas.

import nilearn.datasets

aal = nilearn.datasets.fetch_atlas_aal(version='SPM12')

#my regions of interest indices: 5401, 5301
Fusiform_L = aal.labels.index("Fusiform_L")
Occipital_Inf_L = aal.labels.index("Occipital_Inf_L")

plotting.plot_glass_brain(aal.maps, colorbar=True, title='AAL')

Hi @trylobit and welcome to neurostars!

Here is an example:

import nilearn.datasets
import nilearn.plotting
import nilearn.image

# Load the atlas
aal = nilearn.datasets.fetch_atlas_aal(version='SPM12')
#my regions of interest indices: 5401, 5301
Fusiform_L = 5401
Occipital_Inf_L = 5301
# Load AAL img
aal_img = nilearn.image.load_img(aal.maps)
# Get the affine
aal_affine = aal_img.affine
# Get the data of the map
aal_img_data = aal_img.get_fdata()
# For each region, zero-out any region that is not the region of interest
# Start with Fusiform_L
aal_img_data_fusiform_l = aal_img_data.copy()
aal_img_data_fusiform_l[aal_img_data!=Fusiform_L] = 0
# Now with Occipital_Inf_L
aal_img_data_occipital_inf_l = aal_img_data.copy()
aal_img_data_occipital_inf_l[aal_img_data!=Occipital_Inf_L] = 0
# Save these zeroed-out matrices as new img objects
fusiform_l_img = nilearn.image.new_img_like(aal_img, aal_img_data_fusiform_l, 
                                             affine=aal_affine, copy_header=True)
occipital_inf_l_img = nilearn.image.new_img_like(aal_img, aal_img_data_occipital_inf_l, 
                                                 affine=aal_affine, copy_header=True)
# Plot the imgs
nilearn.plotting.plot_glass_brain(fusiform_l_img, colorbar=True, title='Fusiform_L')
nilearn.plotting.plot_glass_brain(occipital_inf_l_img, colorbar=True, title='Occipital_Inf_L')

Best,
Steven

3 Likes