Skip to content

Commit 16e05f1

Browse files
committed
Small fixes
1 parent 7923490 commit 16e05f1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

flamingo_tools/segmentation/cochlea_mapping.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import math
2+
import warnings
23
from typing import List, Optional, Tuple
34

45
import networkx as nx
@@ -58,7 +59,10 @@ def tonotopic_mapping(
5859
for index, element in zip(labels_subset, centroids_subset):
5960
coords[index] = element
6061

61-
_, graph = graph_connected_components(coords, max_edge_distance, min_component_length)
62+
components, graph = graph_connected_components(coords, max_edge_distance, min_component_length)
63+
if len(components) > 1:
64+
warnings.warn(f"There are {len(components)} connected components, expected 1. "
65+
"Check parameters for post-processing (max_edge_distance, min_component_length).")
6266

6367
unfiltered_graph = graph.copy()
6468

flamingo_tools/segmentation/postprocessing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ def graph_connected_components(coords: dict, max_edge_distance: float, min_compo
352352
graph.remove_node(c)
353353

354354
components = [list(s) for s in nx.connected_components(graph)]
355+
length_components = [len(c) for c in components]
356+
length_components, components = zip(*sorted(zip(length_components, components), reverse=True))
357+
355358
return components, graph
356359

357360

@@ -414,9 +417,6 @@ def components_sgn(
414417

415418
components, _ = graph_connected_components(coords, max_edge_distance, min_component_length)
416419

417-
length_components = [len(c) for c in components]
418-
length_components, components = zip(*sorted(zip(length_components, components), reverse=True))
419-
420420
# add original coordinates closer to eroded component than threshold
421421
if postprocess_threshold is not None:
422422
if postprocess_components is None:

0 commit comments

Comments
 (0)