Skip to content

Comments

distance from points to skeleton surface or centerline#24

Merged
huangziwei merged 7 commits intomainfrom
point2skel
Oct 8, 2025
Merged

distance from points to skeleton surface or centerline#24
huangziwei merged 7 commits intomainfrom
point2skel

Conversation

@huangziwei
Copy link
Collaborator

@huangziwei huangziwei commented Oct 8, 2025

Distance from multiple points to one skeleton

To measure the distance between some points to a skeleton, you can use dx.distance(skel, points), or directly from a Skeleton object:

import skeliner as sk

skel = sk.io.load_npz("../temp_io/720575940550605504.npz")
skel.distance(skel.nodes, mode="centerline")

will returns 0 for all nodes, as the nodes are the centerline.

if we change it a bit:

skel.distance(skel.nodes[100]+ 163, mode="surface"), skel.distance(skel.nodes[100] + 141, mode="centerline")

will return

(7.226243952925699, 148.54367737047386)

Batch distance

a new batch.py module can also find the top k nearest skeletons for multiple points

import skeliner as sk

# load some cells
dsgc = sk.io.load_npz("../../../data/DSGC/720575940567182923/skeleton.npz")
sac_offs = [sk.io.load_npz(f"../../../data/SAC-OFF/{cid}/skeleton.npz") for cid in [720575940547803011, 720575940554656742, 720575940572154471]]

# picks some points for testing
points = []
for i in range(3):
    contact_seeds = sk.pair.find_contact_seeds(dsgc, sac_offs[i])
    points.append(contact_seeds.pos[2])

sk.batch.nearest_skeletons(skeletons=[dsgc] + sac_offs, points=points, k=2)

this will return

[{'point_index': 0,
  'point': [499.73781427336235, 471.3932988369569, 43.056525600559425],
  'matches': [{'skeleton_index': 0,
    'skeleton_id': 720575940567182923,
    'distance': 0.0},
   {'skeleton_index': 1, 'skeleton_id': 720575940547803011, 'distance': 0.0}]},
 {'point_index': 1,
  'point': [420.4119215774796, 399.5634949644302, 55.745175985484856],
  'matches': [{'skeleton_index': 0,
    'skeleton_id': 720575940567182923,
    'distance': 0.0},
   {'skeleton_index': 2, 'skeleton_id': 720575940554656742, 'distance': 0.0}]},
 {'point_index': 2,
  'point': [403.9949115638043, 385.27809952845183, 57.7712639337827],
  'matches': [{'skeleton_index': 0,
    'skeleton_id': 720575940567182923,
    'distance': 0.0},
   {'skeleton_index': 3, 'skeleton_id': 720575940572154471, 'distance': 0.0}]}]

as expected, the test points are the contact seeds between the DSGC and three different OFF SAC, so the DSGC will always be the closest cell to all three points, and each SAC will be closest to one of the point.

@huangziwei huangziwei changed the title wip: distance from points to skeleton surface or centerline distance from points to skeleton surface or centerline Oct 8, 2025
@huangziwei huangziwei merged commit 470fd4a into main Oct 8, 2025
5 checks passed
@huangziwei huangziwei deleted the point2skel branch January 27, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant