Skip to content

Instantly share code, notes, and snippets.

@bthirion
Created January 28, 2022 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bthirion/61630ace721c639e16f459ea212b3e94 to your computer and use it in GitHub Desktop.
Save bthirion/61630ace721c639e16f459ea212b3e94 to your computer and use it in GitHub Desktop.
How to get a difumo label for a given position
from nilearn.datasets import fetch_atlas_difumo
from nilearn.input_data import NiftiSpheresMasker
import numpy as np
d256 = fetch_atlas_difumo(dimension=256)
seeds = [[-52, 14, 0]] # this is your position, you may pick any you wish
masker = NiftiSpheresMasker(seeds=seeds, radius=2).fit()
weights = masker.transform(d256.maps)
label = d256.labels[np.argmax(weights)]
print('label:', label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment