Skip to content

Commit 733de61

Browse files
committed
Save bet/deface masks if specified
Fix typing issues
1 parent b5ef2cc commit 733de61

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

brainles_preprocessing/modality.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def __init__(
139139
else:
140140
self.normalized_defaced_output_path = None
141141

142-
self.steps = {k: None for k in PreprocessorSteps}
142+
self.steps: Dict[PreprocessorSteps, Path | None] = {
143+
k: None for k in PreprocessorSteps
144+
}
143145
self.steps[PreprocessorSteps.INPUT] = self.input_path
144146

145147
@property
@@ -265,7 +267,7 @@ def register(
265267
moving_image_path=self.current,
266268
transformed_image_path=registered,
267269
matrix_path=registered_matrix,
268-
log_file_path=registered_log,
270+
log_file_path=str(registered_log),
269271
)
270272
self.current = registered
271273
self.steps[step] = registered
@@ -394,24 +396,24 @@ def transform(
394396
), "Coregistration must be performed before applying atlas registration."
395397

396398
registrator.transform(
397-
fixed_image_path=fixed_image_path,
398-
moving_image_path=self.steps[PreprocessorSteps.INPUT],
399-
transformed_image_path=transformed,
399+
fixed_image_path=str(fixed_image_path),
400+
moving_image_path=str(self.steps[PreprocessorSteps.INPUT]),
401+
transformed_image_path=str(transformed),
400402
matrix_path=[
401403
self.transformation_paths[
402404
PreprocessorSteps.COREGISTERED
403405
], # coregistration matrix
404406
transformation_matrix_path, # atlas registration matrix
405407
],
406-
log_file_path=transformed_log,
408+
log_file_path=str(transformed_log),
407409
)
408410
else:
409411
registrator.transform(
410-
fixed_image_path=fixed_image_path,
411-
moving_image_path=self.current,
412-
transformed_image_path=transformed,
413-
matrix_path=transformation_matrix_path,
414-
log_file_path=transformed_log,
412+
fixed_image_path=str(fixed_image_path),
413+
moving_image_path=str(self.current),
414+
transformed_image_path=str(transformed),
415+
matrix_path=str(transformation_matrix_path),
416+
log_file_path=str(transformed_log),
415417
)
416418

417419
self.current = transformed
@@ -638,6 +640,12 @@ def extract_brain_region(
638640

639641
if self.bet:
640642
self.current = bet
643+
644+
if self.bet_mask_output_path:
645+
self.save_mask(
646+
mask_path=mask_path,
647+
output_path=self.bet_mask_output_path,
648+
)
641649
return mask_path
642650

643651
def deface(
@@ -684,7 +692,7 @@ def deface(
684692
moving_image_path=self.steps[PreprocessorSteps.BET],
685693
transformed_image_path=atlas_bet,
686694
matrix_path=atlas_bet_M,
687-
log_file_path=defaced_dir_path / "atlas_bet.log",
695+
log_file_path=str(defaced_dir_path / "atlas_bet.log"),
688696
)
689697

690698
deface_mask_atlas = defaced_dir_path / "deface_mask_atlas.nii.gz"
@@ -706,6 +714,12 @@ def deface(
706714
mask_image_path=mask_path,
707715
)
708716

717+
if self.defacing_mask_output_path:
718+
self.save_mask(
719+
mask_path=mask_path,
720+
output_path=self.defacing_mask_output_path,
721+
)
722+
709723
return mask_path
710724
else:
711725
logger.warning(

0 commit comments

Comments
 (0)