[242173]: / inst / deepbleed / preprocess / extract.py

Download this file

40 lines (29 with data), 973 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# @author: msharrock
# version: 0.0.1
'''
Extraction methods for DeepBleed
'''
import os
import nibabel as nib
from fsl.wrappers import fslmaths, bet
def brain(image):
'''
Brain Extraction with FSL
Params:
- image: nifti object, scan to brain extract
Output:
- brain_image: nifti object, extracted brain
'''
affine = image.affine
header = image.header
tmpfile = 'tmpfile.nii.gz'
image.to_filename(tmpfile)
# FSL calls
mask = fslmaths(image).thr('0.000000').uthr('100.000000').bin().fillh().run()
fslmaths(image).mas(mask).run(tmpfile)
bet(tmpfile, tmpfile, fracintensity = 0.01)
mask = fslmaths(tmpfile).bin().fillh().run()
image = fslmaths(image).mas(mask).run()
image = nib.Nifti1Image(image.get_data(), affine, header)
os.remove(tmpfile)
return image