Skip to content

Commit 5bc41bb

Browse files
authored
Merge pull request #21 from BrainLesion/feats/preprocessor
Feats/preprocessor
2 parents 1987c7a + 4c5b009 commit 5bc41bb

File tree

101 files changed

+718
-795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+718
-795
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .brain_extraction import brain_extractor, apply_mask
1+
from .brain_extractor import HDBetExtractor

brainles_preprocessing/brain_extraction/bashhdbet.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

brainles_preprocessing/brain_extraction/brain_extraction.py

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from abc import abstractmethod
2+
3+
import nibabel as nib
4+
import numpy as np
5+
6+
from brainles_hd_bet import run_hd_bet
7+
8+
9+
class BrainExtractor:
10+
@abstractmethod
11+
def extract(
12+
self,
13+
input_image,
14+
output_image,
15+
log_file,
16+
mode,
17+
):
18+
pass
19+
20+
def apply_mask(
21+
self,
22+
input_image,
23+
mask_image,
24+
output_image,
25+
):
26+
"""masks images with brain masks"""
27+
inputnifti = nib.load(input_image)
28+
mask = nib.load(mask_image)
29+
30+
# mask it
31+
masked_file = np.multiply(inputnifti.get_fdata(), mask.get_fdata())
32+
masked_file = nib.Nifti1Image(masked_file, inputnifti.affine, inputnifti.header)
33+
34+
# save it
35+
nib.save(masked_file, output_image)
36+
37+
38+
class HDBetExtractor(BrainExtractor):
39+
def extract(
40+
self,
41+
input_image,
42+
masked_image,
43+
# TODO implement logging!
44+
log_file,
45+
mode="accurate",
46+
):
47+
# GPU + accurate + TTA
48+
"""skullstrips images with HD-BET generates a skullstripped file and mask"""
49+
run_hd_bet(
50+
mri_fnames=[input_image],
51+
output_fnames=[masked_image],
52+
# device=0,
53+
# TODO consider postprocessing
54+
# postprocess=False,
55+
mode=mode,
56+
device=0,
57+
postprocess=False,
58+
do_tta=True,
59+
keep_mask=True,
60+
overwrite=True,
61+
)

brainles_preprocessing/brain_extraction/hdbet.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

brainles_preprocessing/brain_extraction/hdbet_scripts/hd-bet_cpu-fast.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

brainles_preprocessing/brain_extraction/hdbet_scripts/hd-bet_cpu.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

brainles_preprocessing/brain_extraction/hdbet_scripts/hd-bet_gpu.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)