Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions notebooks/atlas_viewer.ipynb

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions scripts/atlas_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import sys
import numpy as np
import nibabel as nb


def getVoxCoord(affine, coord):
"""computes voxel ID from MNI coordinate"""
inverse = np.linalg.inv(affine)
voxCoord = np.dot(inverse, np.hstack((coord, 1)))[:3]
return voxCoord.round().astype('int').tolist()


def getLabel(atlastype, labelID):
"""reads out the name of a specific label"""
if 'freesurfer' in atlastype:
atlastype = 'freesurfer'
labels = np.recfromcsv('../scripts/atlases/labels_%s.csv' % atlastype)
labelIdx = labels.index == labelID
if labelIdx.sum() == 0:
label = 'No_label'
else:
label = labels[labelIdx][0][1]
return label


def readAtlas(atlastype, coordinate, probThresh=5):
"""
Reads specific atlas and returns segment/probability information.
It is possible to threshold a given probability atlas [in percentage].
"""

if atlastype in ['aal',
'freesurfer_desikan-killiany',
'freesurfer_destrieux']:
atlas = nb.load('../scripts/atlases/atlas_%s.mgz' % atlastype)
probAtlas = False
else:
atlas = nb.load('../scripts/atlases/atlas_%s.nii.gz' % atlastype)
probAtlas = True

# Get atlas data and affine matrix
data = atlas.get_data()
affine = atlas.get_affine()

# Get voxel index
voxID = getVoxCoord(affine, coordinate)

# Get Label information
if probAtlas:
probs = data[voxID[0], voxID[1], voxID[2]]
probs[probs < probThresh] = 0
idx = np.where(probs)[0]

# sort list by probability
idx = idx[np.argsort(probs[idx])][::-1]

# get probability and label names
probLabel = []
for i in idx:
label = getLabel(atlastype, i)
probLabel.append([probs[i], label])

# If no labels found
if probLabel == []:
probLabel = [[0, 'No_label']]

return probLabel

else:
labelID = int(data[voxID[0], voxID[1], voxID[2]])
label = getLabel(atlastype, labelID)
return label


def writeOutputToScreen(atlasinfo, coord):
"""Writes output to the sceen"""
print "Segmentation information at {0}:".format(coord)

for ainfo in atlasinfo:
if ainfo[0] in ['aal',
'freesurfer_desikan-killiany',
'freesurfer_destrieux']:
print "{0:<36}{1}".format(ainfo[0], ainfo[1])
else:
for s in ainfo[1]:
print "{0:<30}{1:>4}% {2}".format(ainfo[0], s[0], s[1])
print "\n"


def getAtlasinfo(coord, atlastype='all', probThresh=5, writeToScreen=True):

atlasinfo = []
if atlastype != 'all':
segment = readAtlas(atlastype, coord, probThresh)
atlasinfo.append([atlastype, segment])
else:
for atypes in ['aal',
'freesurfer_desikan-killiany',
'freesurfer_destrieux',
'HarvardOxford',
'Juelich']:
segment = readAtlas(atypes, coord, probThresh)
atlasinfo.append([atypes, segment])

# Write output to screen
if writeToScreen:
writeOutputToScreen(atlasinfo, coord)

return atlasinfo


if __name__ == "__main__":

atlastype = str(sys.argv[1])
coord = [float(x) for x in str(sys.argv[2]).split(',')]
probThresh = int(sys.argv[3])
writeToScreen = bool(sys.argv[4])

getAtlasinfo(coord, atlastype, probThresh, writeToScreen)
Binary file added scripts/atlases/atlas_HarvardOxford.nii.gz
Binary file not shown.
Binary file added scripts/atlases/atlas_Juelich.nii.gz
Binary file not shown.
Binary file added scripts/atlases/atlas_aal.mgz
Binary file not shown.
Binary file not shown.
Binary file added scripts/atlases/atlas_freesurfer_destrieux.mgz
Binary file not shown.
38 changes: 38 additions & 0 deletions scripts/atlases/description_HarvardOxford.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Harvard-Oxford atlas
--------------------

The Harvard-Oxford cortical and subcortical structural atlases are a copy of
FSL's (Version 5.0) under `$FSL_DIR/data/atlases/HarvardOxford/`:
- HarvardOxford-cortl-prob-1mm.nii.gz'
- HarvardOxford-sub-prob-1mm.nii.gz'
For further information see http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Atlases.

The following 4 areas were deleted from the subcortical structural atlas, as
they are already coverd in the cortical structural atlas:
- 'Left Cerebral White Matter'
- 'Left Cerebral Cortex '
- 'Right Cerebral White Matter'
- 'Right Cerebral Cortex '

Afterwards, the cortical and subcortical structural atlases were merged with
the following python code:

import nibabel as nb
cort = nb.load('HarvardOxford-cort-prob-1mm.nii.gz')
sub = nb.load('HarvardOxford-sub-prob-1mm.nii.gz')
newsubdata = sub.get_data()[:, :, :, range(2, 11) + range(13, 21)]
data = np.concatenate((cort.get_data(), newsubdata), axis=3)
affine = cort.get_affine()
nb.Nifti1Image(data.astype('uint8'), affine).to_filename('bladi.nii.gz')


References
----------

Makris N, Goldstein JM, Kennedy D, Hodge SM, Caviness VS, Faraone SV, Tsuang MT, Seidman LJ. Decreased volume of left and total anterior insular lobule in schizophrenia. Schizophr Res. 2006 Apr;83(2-3):155-71

Frazier JA, Chiu S, Breeze JL, Makris N, Lange N, Kennedy DN, Herbert MR, Bent EK, Koneru VK, Dieterich ME, Hodge SM, Rauch SL, Grant PE, Cohen BM, Seidman LJ, Caviness VS, Biederman J. Structural brain magnetic resonance imaging of limbic and thalamic volumes in pediatric bipolar disorder. Am J Psychiatry. 2005 Jul;162(7):1256-65

Desikan RS, Ségonne F, Fischl B, Quinn BT, Dickerson BC, Blacker D, Buckner RL, Dale AM, Maguire RP, Hyman BT, Albert MS, Killiany RJ. An automated labeling system for subdividing the human cerebral cortex on MRI scans into gyral based regions of interest. Neuroimage. 2006 Jul 1;31(3):968-80.

Goldstein JM, Seidman LJ, Makris N, Ahern T, O'Brien LM, Caviness VS Jr, Kennedy DN, Faraone SV, Tsuang MT. Hypothalamic abnormalities in schizophrenia: sex effects and genetic vulnerability. Biol Psychiatry. 2007 Apr 15;61(8):935-45
16 changes: 16 additions & 0 deletions scripts/atlases/description_Juelich.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Juelich atlas
--------------

The Juelich atlas is a direct copy of FSL's (Version 5.0) Juelich atlas under
`$FSL_DIR/data/atlases/Juelich/Juelich-prob-1mm.nii.gz`.
For further information see http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Atlases.


References
----------

Eickhoff, S. B., Stephan, K. E., Mohlberg, H., Grefkes, C., Fink, G. R., Amunts, K., & Zilles, K. (2005). A new SPM toolbox for combining probabilistic cytoarchitectonic maps and functional imaging data. Neuroimage, 25(4), 1325-1335.

Eickhoff, S. B., Heim, S., Zilles, K., & Amunts, K. (2006). Testing anatomically specified hypotheses in functional imaging using cytoarchitectonic maps. Neuroimage, 32(2), 570-582.

Eickhoff, S. B., Paus, T., Caspers, S., Grosbras, M. H., Evans, A. C., Zilles, K., & Amunts, K. (2007). Assignment of functional activations to probabilistic cytoarchitectonic areas revisited. Neuroimage, 36(3), 511-521.
15 changes: 15 additions & 0 deletions scripts/atlases/description_aal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
AAL atlas
---------

The Anatomical Automatic Labeling (AAL) atlas is a copy of SPM12's AAL atlas
(from 25/08/2015) that can be found here: http://www.gin.cnrs.fr/spip-php-article217

The NIfTI file was converted into MGZ-file format with the following command:

mri_convert aal_SPM12/AAL.nii aal.mgz


References
----------

Tzourio-Mazoyer, N., Landeau, B., Papathanassiou, D., Crivello, F., Etard, O., Delcroix, N., ... & Joliot, M. (2002). Automated anatomical labeling of activations in SPM using a macroscopic anatomical parcellation of the MNI MRI single-subject brain. Neuroimage, 15(1), 273-289.
19 changes: 19 additions & 0 deletions scripts/atlases/description_freesurfer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FreeSurfer atlas
----------------

The following two atlases are a copy from FreeSurfer's (v5.3.) subject folder
`cvs_avg35_inMNI152` under `$FREESURFER_HOME/subjects/cvs_avg35_inMNI152/mri`:
- Desikan-Killiany atlas was renamed from aparc+aseg.mgz to
atlas_freesurfer_desikan-killiany.mgz
- Destrieux atlas was renamed from aparc.a2009s+aseg.mgz to
atlas_freesurfer_destrieux.mgz


References
----------

Fischl, B., van der Kouwe, A., Destrieux, C., Halgren, E., Ségonne, F., Salat, D. H., ... & Caviness, V. (2004). Automatically parcellating the human cerebral cortex. Cerebral cortex, 14(1), 11-22.

Destrieux, C., Fischl, B., Dale, A. M., & Halgren, E. (2009). A sulcal depth-based anatomical parcellation of the cerebral cortex. NeuroImage, 47, S151.

Desikan, R. S., Ségonne, F., Fischl, B., Quinn, B. T., Dickerson, B. C., Blacker, D., ... & Albert, M. S. (2006). An automated labeling system for subdividing the human cerebral cortex on MRI scans into gyral based regions of interest. Neuroimage, 31(3), 968-980.
66 changes: 66 additions & 0 deletions scripts/atlases/labels_HarvardOxford.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
index,name
0,Frontal_Pole
1,Insular_Cortex
2,Superior_Frontal_Gyrus
3,Middle_Frontal_Gyrus
4,Inferior_Frontal_Gyrus_pars_triangularis
5,Inferior_Frontal_Gyrus_pars_opercularis
6,Precentral_Gyrus
7,Temporal_Pole
8,Superior_Temporal_Gyrus_anterior_division
9,Superior_Temporal_Gyrus_posterior_division
10,Middle_Temporal_Gyrus_anterior_division
11,Middle_Temporal_Gyrus_posterior_division
12,Middle_Temporal_Gyrus_temporooccipital_part
13,Inferior_Temporal_Gyrus_anterior_division
14,Inferior_Temporal_Gyrus_posterior_division
15,Inferior_Temporal_Gyrus_temporooccipital_part
16,Postcentral_Gyrus
17,Superior_Parietal_Lobule
18,Supramarginal_Gyrus_anterior_division
19,Supramarginal_Gyrus_posterior_division
20,Angular_Gyrus
21,Lateral_Occipital_Cortex_superior_division
22,Lateral_Occipital_Cortex_inferior_division
23,Intracalcarine_Cortex
24,Frontal_Medial_Cortex
25,Juxtapositional_Lobule_Cortex_(formerly_Supplementary_Motor_Cortex)
26,Subcallosal_Cortex
27,Paracingulate_Gyrus
28,Cingulate_Gyrus_anterior_division
29,Cingulate_Gyrus_posterior_division
30,Precuneous_Cortex
31,Cuneal_Cortex
32,Frontal_Orbital_Cortex
33,Parahippocampal_Gyrus_anterior_division
34,Parahippocampal_Gyrus_posterior_division
35,Lingual_Gyrus
36,Temporal_Fusiform_Cortex_anterior_division
37,Temporal_Fusiform_Cortex_posterior_division
38,Temporal_Occipital_Fusiform_Cortex
39,Occipital_Fusiform_Gyrus
40,Frontal_Operculum_Cortex
41,Central_Opercular_Cortex
42,Parietal_Operculum_Cortex
43,Planum_Polare
44,Heschl's_Gyrus_(includes_H1_and_H2)
45,Planum_Temporale
46,Supracalcarine_Cortex
47,Occipital_Pole
48,Left_Lateral_Ventrical
49,Left_Thalamus
50,Left_Caudate
51,Left_Putamen
52,Left_Pallidum
53,Brain-Stem
54,Left_Hippocampus
55,Left_Amygdala
56,Left_Accumbens
57,Right_Lateral_Ventricle
58,Right_Thalamus
59,Right_Caudate
60,Right_Putamen
61,Right_Pallidum
62,Right_Hippocampus
63,Right_Amygdala
64,Right_Accumbens
Loading