Skip to content

Commit 1043a0f

Browse files
anna-grimanna-grim
andauthored
Bug merge detection (#167)
* bug: overcount swcs * refactor: updated merge/split rates --------- Co-authored-by: anna-grim <anna.grim@alleninstitute.org>
1 parent 76bb97d commit 1043a0f

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
"networkx",
2121
"numpy",
2222
"pandas",
23-
"s3fs==2025.6.0",
23+
"s3fs",
2424
"scikit-image",
2525
"tensorstore",
2626
"tifffile",

src/segmentation_skeleton_metrics/skeleton_metrics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ def __call__(self, gt_graphs, results):
713713
for name, graph in gt_graphs.items():
714714
# Compute result
715715
if results["# Splits"][name] > 0:
716-
rate = graph.labeled_run_length / results["# Splits"][name]
716+
rl = util.compute_segmented_run_length(graph, results)
717+
rate = rl / results["# Splits"][name]
717718
else:
718719
rate = np.nan
719720
new_results[name] = round(rate, 2)
@@ -766,7 +767,8 @@ def __call__(self, gt_graphs, results):
766767
for name, graph in gt_graphs.items():
767768
# Compute result
768769
if results["# Merges"][name] > 0:
769-
rate = graph.labeled_run_length / results["# Merges"][name]
770+
rl = util.compute_segmented_run_length(graph, results)
771+
rate = rl / results["# Merges"][name]
770772
else:
771773
rate = np.nan
772774
new_results[name] = round(rate, 2)

src/segmentation_skeleton_metrics/utils/util.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,27 @@ def compute_weighted_avg(df, column_name):
483483
return (values * weights).sum() / weights.sum()
484484

485485

486+
def compute_segmented_run_length(graph, results):
487+
"""
488+
Computes the run length of a graph that was segmented.
489+
490+
Parameters
491+
----------
492+
graph : LabeledGraph
493+
Graph to be evaluated.
494+
results : pandas.DataFrame
495+
Data frame containing skeleton metrics
496+
497+
Returns
498+
-------
499+
float
500+
Run length of a graph that was segmented.
501+
"""
502+
omit_run_length = graph.run_length * results["% Omit"] / 100
503+
split_run_length = graph.run_length * results["% Split"] / 100
504+
return graph.run_length - omit_run_length - split_run_length
505+
506+
486507
def get_segment_id(filename):
487508
"""
488509
Gets the segment ID correspionding to the given filename, assuming that

0 commit comments

Comments
 (0)