Created
December 16, 2020 15:27
-
-
Save xgrg/45647ac75065a1113d5c2f8f69405a09 to your computer and use it in GitHub Desktop.
Create a snapshot from FreeSurfer results
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
from nisnap import snap | |
from nisnap.utils import aseg | |
import sys | |
aparc_fp, bg, snap_fp = sys.argv[1:] | |
filepaths = aseg.__preproc_aseg__(aparc_fp, bg) | |
axes = 'x' | |
figsize = {'x': (23, 15)} | |
rowsize = {'x': 8} | |
n_slices = {'x': 48} | |
labels = aseg.basal_ganglia_labels | |
step = 1 | |
threshold = 75 | |
def __select_slices__(filepaths, axes, rowsize, figsize, step=1, threshold=0): | |
import numpy as np | |
import nibabel as nib | |
from nisnap.utils import slices | |
data = np.asarray(nib.load(filepaths).dataobj) | |
rowsize = slices._fix_rowsize_(axes, rowsize) | |
figsize = slices._fix_figsize_(axes, figsize) | |
sl = slices.cut_slices(data, axes, rowsize, slices=None, step=step, | |
threshold=threshold) | |
sl = {a: [item for sublist in sl[a] for item in sublist] for a in axes} | |
return sl | |
sl = __select_slices__(filepaths, axes, rowsize, | |
figsize, step=step, | |
threshold=threshold) | |
slices = {} | |
for a in axes: | |
margin = int((len(sl[a]) - n_slices[a]) / 2.0) | |
sx = sl[a][margin:len(sl[a]) - margin - 1] | |
slices[a] = sx | |
# Create snapshot with proper options | |
snap.plot_segment(filepaths, axes=axes, bg=bg, opacity=70, | |
slices=slices, animated=False, savefig=snap_fp, | |
figsize=figsize, rowsize=rowsize, | |
contours=True, samebox=True, | |
labels=labels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment