1010The script works iteratively, so the multiple inputs should be in chronological
1111order (and changing the order affects the output). All images should be
1212co-registered.
13+
14+ To obtain labels from binary mask use scil_labels_from_mask.py
15+
16+ WARNING: this script requires all files to have all lesions segmented.
17+ If your data only show new lesions at each timepoints (common in manual
18+ segmentation), use the option --incremental_lesions to merge past timepoints.
19+ T1 = T1, T2 = T1 + T2, T3 = T1 + T2 + T3
1320"""
1421
1522import argparse
1825import nibabel as nib
1926import numpy as np
2027
21- from scilpy .image .labels import get_data_as_labels , harmonize_labels
28+ from scilpy .image .labels import (get_data_as_labels , harmonize_labels ,
29+ get_labels_from_mask )
2230from scilpy .io .utils import (add_overwrite_arg ,
2331 assert_inputs_exist ,
2432 assert_output_dirs_exist_and_empty ,
@@ -48,6 +56,10 @@ def _build_arg_parser():
4856 help = 'Minimum number of overlapping voxels between '
4957 'lesions for them to be considered as the potential '
5058 'match [%(default)s].' )
59+
60+ p .add_argument ('--incremental_lesions' , action = 'store_true' ,
61+ help = 'If lesions files only show new lesions at each '
62+ 'timepoint, this will merge past timepoints.' )
5163 p .add_argument ('--debug_mode' , action = 'store_true' ,
5264 help = 'Add a fake voxel to the corner to ensure consistent '
5365 'colors in MI-Brain.' )
@@ -67,6 +79,19 @@ def main():
6779 imgs = [nib .load (filename ) for filename in args .in_images ]
6880 original_data = [get_data_as_labels (img ) for img in imgs ]
6981
82+ masks = []
83+ if args .incremental_lesions :
84+ for i , data in enumerate (original_data ):
85+ mask = np .zeros_like (data )
86+ mask [data > 0 ] = 1
87+ masks .append (mask )
88+ if i > 0 :
89+ new_data = np .sum (masks , axis = 0 )
90+ new_data [new_data > 0 ] = 1
91+ else :
92+ new_data = mask
93+ original_data [i ] = get_labels_from_mask (new_data )
94+
7095 relabeled_data = harmonize_labels (original_data ,
7196 args .min_voxel_overlap ,
7297 max_adjacency = args .max_adjacency )
0 commit comments