Permalink
Browse files

Merge pull request #285 from alebel14/add_freesurfer_wm_segmentation

use freesurfer segmentation for bbr
  • Loading branch information...
anwarnunez committed Jan 30, 2019
2 parents 7073deb + b5ab4fa commit 2191dfd02f9a9ea9230bd8e9fa3d9c027f801985
Showing with 17 additions and 3 deletions.
  1. +15 −2 cortex/anat.py
  2. +2 −1 cortex/freesurfer.py
@@ -29,10 +29,23 @@ def whitematter(outfile, subject, do_voxelize=False):
voxelize(outfile, subject, surf="wm")
except IOError:
import nibabel
bet = db.get_anat(subject, type='brainmask').get_filename()

try:
cache = tempfile.mkdtemp()
print("Segmenting the brain...")
print ("Attempting to segment the brain with freesurfer...")
bet2 = db.get_anat(subject, type='raw_wm').get_filename()
vol = nibabel.load('{bet2}'.format(bet2=bet2))
vol_data = vol.get_data()
print(vol_data.shape)
new_data = vol_data.copy()
new_data[new_data==250] = 0
new_data[new_data>0] = 1
wm_freesurf = nibabel.Nifti1Image(new_data, vol.affine, header=vol.header)
wm_freesurf.to_filename(outfile)
except:
cache = tempfile.mkdtemp()
print("Attempt with freesurfer failed, trying again with FSL...")
bet = db.get_anat(subject, type='brainmask').get_filename()
cmd = '{fsl_prefix}fast -o {cache}/fast {bet}'.format(fsl_prefix=fsl_prefix, cache=cache, bet=bet)
assert sp.call(cmd, shell=True) == 0, "Error calling fsl-fast"

@@ -165,7 +165,8 @@ def import_subj(subject, sname=None, freesurfer_subject_dir=None, whitematter_su
fspath = os.path.join(freesurfer_subject_dir, subject, 'mri')
curvs = os.path.join(freesurfer_subject_dir, subject, 'surf', '{hemi}.{name}')

for fsname, name in dict(T1="raw", aseg="aseg").items():
#import anatomicals
for fsname, name in dict(T1="raw", aseg="aseg", wm="raw_wm").items():
path = os.path.join(fspath, "{fsname}.mgz").format(fsname=fsname)
out = anats.format(subj=sname, name=name)
cmd = "mri_convert {path} {out}".format(path=path, out=out)

0 comments on commit 2191dfd

Please sign in to comment.