-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import nibabel as nb | ||
import numpy as np | ||
from collections import defaultdict | ||
|
||
|
||
# The following code was adapted from Satra Gosh's sad_figures.py script | ||
# located at https://github.com/satra/sad/blob/master/sad_figures.py | ||
|
||
# get cluster coordinates caculate the volume and the center of mass | ||
# of the brain regions in img | ||
|
||
def get_coords(img, affine): | ||
coords = defaultdict(dict) | ||
|
||
# determine the unique regions | ||
labels = np.setdiff1d(np.unique(img.ravel()), [0]) | ||
|
||
for label in labels: | ||
|
||
# calculate the volume of the region | ||
coords[label]["Vol"]=np.sum(img==label) | ||
|
||
# calculate the center of mass (CoM) of the region | ||
coords[label]["CoM"]=np.dot(affine,\ | ||
np.hstack((np.mean(np.asarray(np.nonzero(img==label)),\ | ||
axis = 1),1)))[:3].tolist() | ||
|
||
return (coords) | ||
|