-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from BrainLesion/feats/preprocessor
Feats/preprocessor
- Loading branch information
Showing
101 changed files
with
718 additions
and
795 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 |
---|---|---|
@@ -1 +1 @@ | ||
from .brain_extraction import brain_extractor, apply_mask | ||
from .brain_extractor import HDBetExtractor |
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
brainles_preprocessing/brain_extraction/brain_extraction.py
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
brainles_preprocessing/brain_extraction/brain_extractor.py
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,61 @@ | ||
from abc import abstractmethod | ||
|
||
import nibabel as nib | ||
import numpy as np | ||
|
||
from brainles_hd_bet import run_hd_bet | ||
|
||
|
||
class BrainExtractor: | ||
@abstractmethod | ||
def extract( | ||
self, | ||
input_image, | ||
output_image, | ||
log_file, | ||
mode, | ||
): | ||
pass | ||
|
||
def apply_mask( | ||
self, | ||
input_image, | ||
mask_image, | ||
output_image, | ||
): | ||
"""masks images with brain masks""" | ||
inputnifti = nib.load(input_image) | ||
mask = nib.load(mask_image) | ||
|
||
# mask it | ||
masked_file = np.multiply(inputnifti.get_fdata(), mask.get_fdata()) | ||
masked_file = nib.Nifti1Image(masked_file, inputnifti.affine, inputnifti.header) | ||
|
||
# save it | ||
nib.save(masked_file, output_image) | ||
|
||
|
||
class HDBetExtractor(BrainExtractor): | ||
def extract( | ||
self, | ||
input_image, | ||
masked_image, | ||
# TODO implement logging! | ||
log_file, | ||
mode="accurate", | ||
): | ||
# GPU + accurate + TTA | ||
"""skullstrips images with HD-BET generates a skullstripped file and mask""" | ||
run_hd_bet( | ||
mri_fnames=[input_image], | ||
output_fnames=[masked_image], | ||
# device=0, | ||
# TODO consider postprocessing | ||
# postprocess=False, | ||
mode=mode, | ||
device=0, | ||
postprocess=False, | ||
do_tta=True, | ||
keep_mask=True, | ||
overwrite=True, | ||
) |
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
brainles_preprocessing/brain_extraction/hdbet_scripts/hd-bet_cpu-fast.sh
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
brainles_preprocessing/brain_extraction/hdbet_scripts/hd-bet_cpu.sh
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
brainles_preprocessing/brain_extraction/hdbet_scripts/hd-bet_gpu.sh
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.