Summary of what happened:
I would like to convert a volumetric atlas to a surface based atlas using the new functionalities from nilearn 0.11.1. Even though I use interpolation='nearest'
the array after volume-to-surface conversion contains invalid ids (numbers must range from 0-48)
Command used (and if a helper script was used, a link to the helper script or the command generated):
import numpy as np
from nilearn.image import load_img
from nilearn.surface import SurfaceImage
from nilearn import datasets
from nilearn.plotting import view_surf
# Load a volumetric atlas (example: Harvard-Oxford cortical atlas)
atlas = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-1mm')
atlas_img = load_img(atlas.maps)
# sanity check print number of unique labels
atlas_img_data = atlas_img.get_fdata()
uniques,counts = np.unique(atlas_img_data,return_counts=True)
print(f"Volumetric atlas has {len(counts)} unique ids")
# Load the fsaverage mesh(s)
fsaverage_meshes = datasets.load_fsaverage()
# Question: How to convert volumetric to surface with only valid atlas
# region ids?
atlas_img_surf = SurfaceImage.from_volume(
mesh=fsaverage_meshes["pial"],
volume_img=atlas_img,
interpolation='nearest'
)
# check if it worked
for hemi, data in atlas_img_surf.data.parts.items():
uniques,counts = np.unique(data,return_counts=True)
print(f"{hemi} hemi of surface atlas has {len(counts)} unique ids")
EDIT: The conversion must only be âgood enoughâ as I am only interested in visualization (I donât want to use the converted atlas for analyses).