Skip to content

Commit 0995c2e

Browse files
author
GOESTERN-1107078
committed
skeleton postprocessing cosmetic changes
1 parent 54f32cd commit 0995c2e

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

examples/skeleton/instance_segmentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import numpy as np
1212

1313
from bioimage_cpp.graph import connected_components
14-
from bioimage_cpp.skeleton import clean_graph, draw_instances, skeleton_to_graph, teasar
14+
from bioimage_cpp.skeleton import clean_filament_graph, draw_instances, skeleton_to_graph, teasar
1515

1616

1717
def parse_args():
@@ -78,7 +78,7 @@ def main():
7878
number_of_threads=args.number_of_threads,
7979
)
8080

81-
vertices, edges, radii = clean_graph(
81+
vertices, edges, radii = clean_filament_graph(
8282
raw_vertices, raw_edges, radii=raw_radii,
8383
direction_span=args.direction_span, min_through_angle=args.min_through_angle,
8484
min_branch_angle=args.min_branch_angle, tick_length=args.tick_length,

src/bioimage_cpp/skeleton/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .._validation import strict_index
1111
from ..distance._distance import _as_binary_input, _normalize_sampling, _normalize_threads
1212
from ._graph import skeleton_to_graph
13-
from .postprocessing import clean_graph, draw_instances, join_close_components, remove_ticks
13+
from .postprocessing import clean_filament_graph, draw_instances, join_close_components, remove_ticks
1414

1515

1616
_TEASAR_LABELS_BY_DTYPE = {
@@ -206,4 +206,4 @@ def teasar_labels(
206206
from . import distributed
207207

208208

209-
__all__ = ["clean_graph", "distributed", "draw_instances", "join_close_components", "remove_ticks", "skeleton_to_graph", "teasar", "teasar_labels"]
209+
__all__ = ["clean_filament_graph", "distributed", "draw_instances", "join_close_components", "remove_ticks", "skeleton_to_graph", "teasar", "teasar_labels"]

src/bioimage_cpp/skeleton/postprocessing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _compact(vertices, edges, radii):
4545
return vertices[used], remap[edges], radii
4646

4747

48-
def split_degree3(v, graph, vertices, direction_span=1, min_branch_angle=30.0):
48+
def _split_degree3(v, graph, vertices, direction_span=1, min_branch_angle=30.0):
4949
adj = np.asarray(graph.node_adjacency(int(v)))
5050
if adj.shape[0] != 3:
5151
return None
@@ -64,7 +64,7 @@ def split_degree3(v, graph, vertices, direction_span=1, min_branch_angle=30.0):
6464
return [int(edge_ids[odd])]
6565

6666

67-
def split_degree4(v, graph, vertices, direction_span=1, min_through_angle=160.0):
67+
def _split_degree4(v, graph, vertices, direction_span=1, min_through_angle=160.0):
6868
adj = np.asarray(graph.node_adjacency(int(v)))
6969
if adj.shape[0] != 4:
7070
return None
@@ -81,7 +81,7 @@ def split_degree4(v, graph, vertices, direction_span=1, min_through_angle=160.0)
8181
return [int(edge_ids[k]) for k in pair_b]
8282

8383

84-
def clean_graph(
84+
def clean_filament_graph(
8585
vertices: np.ndarray,
8686
edges: np.ndarray,
8787
radii: np.ndarray | None = None,
@@ -159,11 +159,11 @@ def _snapshot(name):
159159

160160
splits, prune_edges = [], set()
161161
for v in np.where(degrees == 3)[0]:
162-
ids = split_degree3(v, graph, vertices, direction_span, min_branch_angle)
162+
ids = _split_degree3(v, graph, vertices, direction_span, min_branch_angle)
163163
if ids:
164164
prune_edges.update(ids)
165165
for v in np.where(degrees == 4)[0]:
166-
ids = split_degree4(v, graph, vertices, direction_span, min_through_angle)
166+
ids = _split_degree4(v, graph, vertices, direction_span, min_through_angle)
167167
if ids:
168168
splits.append((int(v), ids))
169169

@@ -479,4 +479,4 @@ def draw_instances(vertices, edges, labels, shape, radius=1):
479479
return volume
480480

481481

482-
__all__ = ["clean_graph", "draw_instances", "join_close_components", "remove_ticks"]
482+
__all__ = ["clean_filament_graph", "draw_instances", "join_close_components", "remove_ticks"]

tests/skeleton/test_postprocessing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
import bioimage_cpp as bic
5-
from bioimage_cpp.skeleton.postprocessing import split_degree3, split_degree4
5+
from bioimage_cpp.skeleton.postprocessing import _split_degree3, _split_degree4
66

77

88
def _graph(vertices, edges):
@@ -22,7 +22,7 @@ def test_split_degree3_splits_odd_arm():
2222
[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0]],
2323
[[0, 1], [0, 2], [0, 3]],
2424
)
25-
assert split_degree3(0, graph, vertices, direction_span=1, min_branch_angle=30.0) == [2]
25+
assert _split_degree3(0, graph, vertices, direction_span=1, min_branch_angle=30.0) == [2]
2626

2727

2828
def test_split_degree3_keeps_collinear_arm():
@@ -31,7 +31,7 @@ def test_split_degree3_keeps_collinear_arm():
3131
[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0], [0.0, 1.0, 10.0]],
3232
[[0, 1], [0, 2], [0, 3]],
3333
)
34-
assert split_degree3(0, graph, vertices, direction_span=1, min_branch_angle=30.0) is None
34+
assert _split_degree3(0, graph, vertices, direction_span=1, min_branch_angle=30.0) is None
3535

3636

3737
def test_split_degree4_splits_through_pair():
@@ -40,7 +40,7 @@ def test_split_degree4_splits_through_pair():
4040
[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0], [0.0, -1.0, 0.0]],
4141
[[0, 1], [0, 2], [0, 3], [0, 4]],
4242
)
43-
result = split_degree4(0, graph, vertices, direction_span=1, min_through_angle=170.0)
43+
result = _split_degree4(0, graph, vertices, direction_span=1, min_through_angle=170.0)
4444
assert set(result) in ({0, 1}, {2, 3})
4545

4646

@@ -52,7 +52,7 @@ def test_split_degree4_keeps_non_collinear_crossing():
5252
np.concatenate([[[0.0, 0.0, 0.0]], arms]),
5353
[[0, 1], [0, 2], [0, 3], [0, 4]],
5454
)
55-
assert split_degree4(0, graph, vertices, direction_span=1, min_through_angle=170.0) is None
55+
assert _split_degree4(0, graph, vertices, direction_span=1, min_through_angle=170.0) is None
5656

5757

5858
@pytest.mark.parametrize(
@@ -141,7 +141,7 @@ def test_clean_graph_splits_crossing():
141141

142142
assert _component_count(vertices, edges) == 1
143143

144-
out_vertices, out_edges, out_radii = bic.skeleton.clean_graph(
144+
out_vertices, out_edges, out_radii = bic.skeleton.clean_filament_graph(
145145
vertices, edges, radii=radii, direction_span=1, tick_length=0.0, join_dist=0.0,
146146
)
147147

0 commit comments

Comments
 (0)