@@ -53,16 +53,13 @@ class SkeletonMetric:
5353
5454 def __init__ (
5555 self ,
56- gt_pointer ,
57- label_mask ,
56+ gt_graphs ,
57+ fragment_graphs ,
58+ label_handler ,
5859 output_dir ,
5960 anisotropy = (1.0 , 1.0 , 1.0 ),
60- connections_path = None ,
61- fragments_pointer = None ,
6261 save_merges = False ,
6362 save_fragments = False ,
64- use_anisotropy = False ,
65- valid_labels = None ,
6663 verbose = True
6764 ):
6865 """
@@ -71,59 +68,41 @@ def __init__(
7168
7269 Parameters
7370 ----------
74- gt_pointer : Any
75- Pointer to ground truth SWC files, see "swc_util.Reader" for
76- documentation. These SWC files are assumed to be stored in voxel
77- coordinates .
78- label_mask : ImageReader
79- Predicted segmentation .
80- output_dir : str
71+ gt_graphs : SkeletonGraph
72+ ...
73+ fragment_graphs ; SkeletonGraph
74+ .. .
75+ label_handler : LabelHandler
76+ .. .
77+ output_dir : str
8178 Path to directory wehere results are written.
8279 anisotropy : Tuple[float], optional
8380 Image to physical coordinate scaling factors applied to SWC files
8481 stored at "fragments_pointer". Default is (1.0, 1.0, 1.0).
85- connections_path : str, optional
86- Path to a txt file containing pairs of segment IDs that represents
87- fragments that were merged. Default is None.
88- fragments_pointer : Any, optional
89- Pointer to SWC files corresponding to "label_mask", see
90- "swc_util.Reader" for documentation. Notes: (1) "anisotropy" is
91- applied to these SWC files and (2) these SWC files are required
92- for counting merges. Default is None.
82+ output_dir : str
83+ ...
9384 save_merges: bool, optional
9485 Indication of whether to save fragments with a merge mistake.
9586 Default is None.
9687 save_fragments : bool, optional
9788 Indication of whether to save fragments that project onto each
9889 ground truth skeleton. Default is False.
99- valid_labels : Set[int], optional
100- Segment IDs that can be assigned to nodes. This argument accounts
101- for segments that were been removed due to some type of filtering.
102- Default is None.
103- use_anisotropy : bool, optional
104- Indication of whether coordinates in fragment SWC files should be
105- converted from physical to image coordinates using the given
106- anisotropy. Default is False.
10790 verbose : bool, optional
10891 Indication of whether to printout updates. Default is True.
10992 """
11093 # Instance attributes
11194 self .anisotropy = anisotropy
112- self .connections_path = connections_path
11395 self .output_dir = output_dir
11496 self .save_merges = save_merges
11597 self .save_fragments = save_fragments
116- self .use_anisotropy = use_anisotropy
11798 self .verbose = verbose
11899
119- # Label handler
120- self .label_handler = LabelHandler (
121- connections_path = connections_path , valid_labels = valid_labels
122- )
100+ # Core data structures
101+ self .graphs = gt_graphs
102+ self . fragment_graphs = fragment_graphs
103+ self . label_handler = label_handler
123104
124- # Load data
125- self .load_groundtruth (gt_pointer , label_mask )
126- self .load_fragments (fragments_pointer )
105+ self .gt_graphs = deepcopy (self .graphs )
127106
128107 # Initialize metrics
129108 util .mkdir (output_dir )
@@ -151,74 +130,6 @@ def __init__(
151130 self .metrics ["# Splits" ] = 0
152131 self .metrics ["SWC Name" ] = self .metrics .index
153132
154- # --- Load Data ---
155- def load_groundtruth (self , swc_pointer , label_mask ):
156- """
157- Loads ground truth graphs and initializes the "graphs" attribute.
158-
159- Parameters
160- ----------
161- swc_pointer : Any
162- Pointer to ground truth SWC files.
163- label_mask : ImageReader
164- Predicted segmentation mask.
165- """
166- if self .verbose :
167- print ("\n (1) Load Ground Truth" )
168-
169- # Build graphs
170- graph_loader = gutil .GraphLoader (
171- anisotropy = self .anisotropy ,
172- is_groundtruth = True ,
173- label_handler = self .label_handler ,
174- label_mask = label_mask ,
175- use_anisotropy = False ,
176- )
177- self .graphs = graph_loader .run (swc_pointer )
178-
179- # Save initial graphs (if applicable)
180- if self .save_merges :
181- self .gt_graphs = deepcopy (self .graphs )
182-
183- def load_fragments (self , swc_pointer ):
184- """
185- Loads fragments generated from the segmentation and initializes the
186- "fragment_graphs" attribute.
187-
188- Parameters
189- ----------
190- swc_pointer : Any
191- Pointer to predicted SWC files if provided.
192- """
193- if self .verbose :
194- print ("\n (2) Load Fragments" )
195-
196- if swc_pointer :
197- graph_loader = gutil .GraphLoader (
198- anisotropy = self .anisotropy ,
199- is_groundtruth = False ,
200- selected_ids = self .get_all_node_labels (),
201- use_anisotropy = self .use_anisotropy ,
202- )
203- self .fragment_graphs = graph_loader .run (swc_pointer )
204- else :
205- self .fragment_graphs = None
206-
207- def get_all_node_labels (self ):
208- """
209- Gets the set of unique node labels across all graphs in "self.graphs".
210-
211- Returns
212- -------
213- Set[int]
214- Unique node labels across all graphs.
215- """
216- all_node_labels = set ()
217- for graph in self .graphs .values ():
218- node_labels = self .label_handler .get_node_labels (graph )
219- all_node_labels = all_node_labels .union (node_labels )
220- return all_node_labels
221-
222133 def init_writers (self ):
223134 """
224135 Initializes "self.merge_writer" attribute by setting up a directory for
@@ -259,7 +170,7 @@ def run(self):
259170 self .compute_erl ()
260171
261172 # Save results
262- prefix = "corrected-" if self .connections_path else ""
173+ prefix = "corrected-" if self .label_handler . use_mapping () else ""
263174 path = f"{ self .output_dir } /{ prefix } results.csv"
264175 if self .fragment_graphs is None :
265176 self .metrics = self .metrics .drop ("# Merges" , axis = 1 )
0 commit comments