Get region of brain from coordinates

How to extract the brain region label from a given brain region’s coordinate ? Is there a way to do this in nilearn presently ?

So far, I have done as below:

from nilearn.regions import RegionExtractor
from nilearn.decomposition import DictLearning
dictlearn=DictLearning(smoothing_fwhm=6.,
                      memory="nilearn_cache", memory_level=2,
                      random_state=0, verbose=10, mask_strategy='background')
dictlearn.fit(pitt_autism_ds.func_preproc)
dictlearn_components_img=dictlearn.masker_.inverse_transform(dictlearn.components_)

from nilearn import plotting

extractor = RegionExtractor(dictlearn_components_img, threshold=0.5,
                        thresholding_strategy='ratio_n_voxels',
                        extractor='local_regions',
                        standardize=True, min_region_size=1350, verbose=10)
# Just call fit() to process for regions extraction
extractor.fit()
# Extracted regions are stored in regions_img_
regions_extracted_img = extractor.regions_img_
# Each region index is stored in index_
regions_index = extractor.index_
# Total number of regions extracted
n_regions_extracted = regions_extracted_img.shape[-1]

# Visualization of region extraction results
title = ('%d regions are extracted from %d components.'
     '\nEach separate color of region indicates extracted region'
     % (n_regions_extracted, 20))
plotting.plot_prob_atlas(regions_extracted_img, view_type='filled_contours',
                     title=title)
plotting.show()

for region in image.iter_img(regions_extracted_img):
    plotting.plot_stat_map(region, display_mode='x', colorbar=True)
    plotting.show()

However i want to display the label along with each brain region.

You can retrieve the numpy arrays with the labels, and use nilearn.image.coord_transform to transform from brain coordinates (in mm) to array ccordinates (in voxel indices): see the example at the end of the docstring:
http://nilearn.github.io/modules/generated/nilearn.image.coord_transform.html

1 Like

@GaelVaroquaux sure, but in the above code, we do not get labels from the extractor object, do we ? The extractor object merely has the regions_img_ which contains the affine and x,y,z coordinates. Does coord_transform provide a way to get the region’s name(label) from the x,y,z or affine input ?

but in the above code, we do not get labels from the extractor object, do we ?

@MeenVen You are right, the above code does not get labels. It gives the extractor regions in a Nifti image.

Does coord_transform provide a way to get the region’s name(label) from the x,y,z or affine input ?

No. As Gael said it is useful to transform from brain coordinates (in mm) to array ccordinates (in voxel indices).

Presently, this is not implemented in Nilearn. Given MNI coordinates of regions returns labels (regions names).

@KamalakerD thank you. That’s what i thought too. But is there absolutely no way to do this ? given it is possible to extract region labels for correlation matrix as follows:

dataset = datasets.fetch_atlas_harvard_oxford('cort-maxprob-thr25-2mm')
labels=dataset.labels

masker = NiftiLabelsMasker(labels_img=atlas_filename,smoothing_fwhm=8, memory='nilearn_cache', 
memory_level=1, verbose=5, standardize=True)
d1=masker.fit_transform(dataset.func_preproc[0])
d2=masker.fit_transform(dataset.func_preproc[0])

typical=[d1,d2]
correlation_measure=ConnectivityMeasure(kind='correlation')
correlation_matrices=correlation_measure.fit_transform(typical)

for correlation_matrix in correlation_matrices:
    np.fill_diagonal(correlation_matrix, 0)
    plotting.plot_matrix(correlation_matrix, figure=(10,8), labels=labels[1:], vmax=0.8, vmin=-0.8)
    plotting.show()

Btw, http://www.talairach.org/labels.txt has a java software that gives the labels given MNI coords. Has anyone used this tool before ?

Hi Gael. I have a single nifti (nii) file and I just want to extract the brain coordinates (in mm) for all voxels (i.e. the whole nii volume). How can I do that using nilearn/nibabel? Thank you