Healing fragmented skeletons¶
Reconstructed skeletons are often broken into several disconnected fragments. Healing means finding the shortest set of new edges that stitches those fragments back into a single rooted tree.
heal_skeleton does the whole job: it finds the
minimal-length bridges between connected components and regenerates the parent
vector. stitch_fragments is the lower-level
half, returning just the bridging edges if you want to inspect or filter them
before rewiring.
import navis_fastcore as fastcore
new_parent_ids = fastcore.heal_skeleton(node_ids, parent_ids, coords)
Two options are worth knowing about:
max_distcaps how long a single new edge may be. Gaps wider than that are left alone, so the result can still be fragmented — which is usually what you want, as bridging a huge gap is more likely to be wrong than right.use_radiustakes node radii into account when measuring distances, which prefers connecting fragments of similar calibre over merely nearby ones. Pass a float rather thanTrueto weight how much influence radius gets. Note thatmax_distis then measured in that augmented space too.
API¶
navis_fastcore.heal_skeleton(node_ids, parent_ids, coords, method='ALL', max_dist=None, min_size=None, mask=None, radius=None, use_radius=False)
¶
Heal a fragmented skeleton by reconnecting its fragments.
Rust re-implementation of the core of navis.heal_skeleton: it finds the
minimal-length set of bridges between the skeleton's connected components
(see :func:stitch_fragments) and regenerates a single rooted tree.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
coords
|
TYPE:
|
method
|
TYPE:
|
max_dist
|
TYPE:
|
min_size
|
TYPE:
|
mask
|
TYPE:
|
radius
|
TYPE:
|
use_radius
|
|
| RETURNS | DESCRIPTION |
|---|---|
new_parent_ids
|
New parent IDs, in the same order as
TYPE:
|
Examples:
>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(4)
>>> parent_ids = np.array([-1, 0, -1, 2]) # two fragments
>>> coords = np.array([[0, 0, 0], [1, 0, 0], [10, 0, 0], [11, 0, 0]], dtype=float)
>>> fastcore.heal_skeleton(node_ids, parent_ids, coords)
array([-1, 0, 1, 2])
navis_fastcore.stitch_fragments(node_ids, parent_ids, coords, mask=None, max_dist=None, radius=None, use_radius=False)
¶
Find minimal-length edges to reconnect a fragmented skeleton.
This is the low-level primitive behind :func:heal_skeleton: given a
skeleton that consists of several disconnected fragments (connected
components), it returns the set of new edges that would connect those
fragments into a single tree while minimising the total added length. It
does not modify the skeleton.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
coords
|
TYPE:
|
mask
|
TYPE:
|
max_dist
|
TYPE:
|
radius
|
TYPE:
|
use_radius
|
|
| RETURNS | DESCRIPTION |
|---|---|
edges
|
Pairs of node IDs to connect. At most
TYPE:
|
distances
|
Euclidean length of each new edge. If
TYPE:
|
Examples:
>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(4)
>>> # Two fragments: {0, 1} and {2, 3}
>>> parent_ids = np.array([-1, 0, -1, 2])
>>> coords = np.array([[0, 0, 0], [1, 0, 0], [10, 0, 0], [11, 0, 0]], dtype=float)
>>> edges, dists = fastcore.stitch_fragments(node_ids, parent_ids, coords)
>>> edges
array([[1, 2]])
>>> dists
array([9.], dtype=float32)