Skip to content

Commit af4acd8

Browse files
authored
Merge pull request #38 from BrainLesion/nicer_hdbet_test
Nicer hdbet test
2 parents 052c9c0 + 9c5fa05 commit af4acd8

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

brainles_preprocessing/brain_extraction/brain_extractor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def extract(
8888
+ "_mask.nii.gz"
8989
)
9090

91-
copyfile(
92-
src=hdbet_mask_path,
93-
dst=brain_mask_path,
94-
)
91+
if hdbet_mask_path != brain_mask_path:
92+
copyfile(
93+
src=hdbet_mask_path,
94+
dst=brain_mask_path,
95+
)

tests/test_brain_extractor.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ def setUp(self):
1616

1717
self.brain_extractor = HDBetExtractor()
1818
self.input_image_path = input_dir + "/tcia_example_t1c.nii.gz"
19+
self.input_brain_mask_path = input_dir + "/bet_tcia_example_t1c_mask.nii.gz"
1920
self.masked_image_path = self.output_dir + "/bet_tcia_example_t1c.nii.gz"
20-
self.brain_mask_path = self.output_dir + "/bet_tcia_example_t1c_masked.nii.gz"
21+
self.brain_mask_path = self.output_dir + "/bet_tcia_example_t1c_mask.nii.gz"
22+
self.masked_again_image_path = (
23+
self.output_dir + "/bet_tcia_example_t1c_masked2.nii.gz"
24+
)
2125

2226
print(self.input_image_path)
2327
print(self.masked_image_path)
@@ -26,6 +30,7 @@ def tearDown(self):
2630
# Clean up created files if they exist
2731
shutil.rmtree(self.output_dir)
2832

33+
2934
def test_extract_creates_output_files(self):
3035
# we try to run the fastest possible skullstripping on GPU
3136
self.brain_extractor.extract(
@@ -47,11 +52,12 @@ def test_extract_creates_output_files(self):
4752
)
4853

4954
def test_apply_mask_creates_output_file(self):
50-
# self.brain_extractor.apply_mask(
51-
# self.input_image, self.mask_image, self.output_image
52-
# )
53-
# self.assertTrue(
54-
# os.path.exists(self.output_image_path),
55-
# "Output image file was not created in apply_mask.",
56-
# )
57-
...
55+
self.brain_extractor.apply_mask(
56+
input_image_path=self.input_image_path,
57+
mask_image_path=self.input_brain_mask_path,
58+
masked_image_path=self.masked_again_image_path,
59+
)
60+
self.assertTrue(
61+
os.path.exists(self.masked_again_image_path),
62+
"Output image file was not created in apply_mask.",
63+
)
23 KB
Binary file not shown.

0 commit comments

Comments
 (0)