# How to use dijkstra3d - 5 common examples

## To help you get started, we’ve selected a few dijkstra3d examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately. seung-lab / kimimaro / kimimaro / trace.py View on Github ``````if root is None:
if soma_mode:
root = find_soma_root(DBF, dbf_max)
soma_radius = dbf_max * soma_invalidation_scale + soma_invalidation_const
else:
root = find_root(labels, anisotropy)

if root is None:
return PrecomputedSkeleton()

# DBF: Distance to Boundary Field
# DAF: Distance from any voxel Field (distance from root field)
# PDRF: Penalized Distance from Root Field
DBF = kimimaro.skeletontricks.zero2inf(DBF) # DBF[ DBF == 0 ] = np.inf
DAF = dijkstra3d.euclidean_distance_field(labels, root, anisotropy=anisotropy)
DAF = kimimaro.skeletontricks.inf2zero(DAF) # DAF[ DAF == np.inf ] = 0
PDRF = compute_pdrf(dbf_max, pdrf_scale, pdrf_exponent, DBF, DAF)

# Use dijkstra propogation w/o a target to generate a field of
# pointers from each voxel to its parent. Then we can rapidly
# compute multiple paths by simply hopping pointers using path_from_parents
if not fix_branching:
parents = dijkstra3d.parental_field(PDRF, root)
del PDRF
else:
parents = PDRF

if soma_mode:
invalidated, labels = kimimaro.skeletontricks.roll_invalidation_ball(
labels, DBF, np.array([root], dtype=np.uint32),
scale=soma_invalidation_scale,`````` seung-lab / kimimaro / kimimaro / trace.py View on Github ``````def find_root(labels, anisotropy):
"""
"4.4 DAF:  Compute distance from any voxel field"
Compute DAF, but we immediately convert to the PDRF
The extremal point of the PDRF is a valid root node
even if the DAF is computed from an arbitrary pixel.
"""
any_voxel = kimimaro.skeletontricks.first_label(labels)
if any_voxel is None:
return None

DAF = dijkstra3d.euclidean_distance_field(
np.asfortranarray(labels), any_voxel, anisotropy=anisotropy)
return kimimaro.skeletontricks.find_target(labels, DAF)`````` seung-lab / kimimaro / kimimaro / trace.py View on Github ``````if len(manual_targets_before) + len(manual_targets_after) &gt;= max_paths:
return []

while (valid_labels &gt; 0 or manual_targets_before or manual_targets_after) \
and len(paths) &lt; max_paths:

if manual_targets_before:
target = manual_targets_before.pop()
elif valid_labels == 0:
target = manual_targets_after.pop()
else:
target = kimimaro.skeletontricks.find_target(labels, DAF)

if fix_branching:
path = dijkstra3d.dijkstra(parents, root, target)
else:
path = dijkstra3d.path_from_parents(parents, target)

if soma_mode:
dist_to_soma_root = np.linalg.norm(anisotropy * (path - root), axis=1)
# remove all path points which are within soma_radius of root
path = np.concatenate(
)

if valid_labels &gt; 0:
invalidated, labels = kimimaro.skeletontricks.roll_invalidation_cube(
labels, DBF, path, scale, const,
anisotropy=anisotropy, invalid_vertices=invalid_vertices,
)
valid_labels -= invalidated`````` seung-lab / kimimaro / kimimaro / trace.py View on Github ``````return []

while (valid_labels &gt; 0 or manual_targets_before or manual_targets_after) \
and len(paths) &lt; max_paths:

if manual_targets_before:
target = manual_targets_before.pop()
elif valid_labels == 0:
target = manual_targets_after.pop()
else:
target = kimimaro.skeletontricks.find_target(labels, DAF)

if fix_branching:
path = dijkstra3d.dijkstra(parents, root, target)
else:
path = dijkstra3d.path_from_parents(parents, target)

if soma_mode:
dist_to_soma_root = np.linalg.norm(anisotropy * (path - root), axis=1)
# remove all path points which are within soma_radius of root
path = np.concatenate(
)

if valid_labels &gt; 0:
invalidated, labels = kimimaro.skeletontricks.roll_invalidation_cube(
labels, DBF, path, scale, const,
anisotropy=anisotropy, invalid_vertices=invalid_vertices,
)
valid_labels -= invalidated

for vertex in path:`````` seung-lab / kimimaro / kimimaro / trace.py View on Github ``````if root is None:
return PrecomputedSkeleton()

# DBF: Distance to Boundary Field
# DAF: Distance from any voxel Field (distance from root field)
# PDRF: Penalized Distance from Root Field
DBF = kimimaro.skeletontricks.zero2inf(DBF) # DBF[ DBF == 0 ] = np.inf
DAF = dijkstra3d.euclidean_distance_field(labels, root, anisotropy=anisotropy)
DAF = kimimaro.skeletontricks.inf2zero(DAF) # DAF[ DAF == np.inf ] = 0
PDRF = compute_pdrf(dbf_max, pdrf_scale, pdrf_exponent, DBF, DAF)

# Use dijkstra propogation w/o a target to generate a field of
# pointers from each voxel to its parent. Then we can rapidly
# compute multiple paths by simply hopping pointers using path_from_parents
if not fix_branching:
parents = dijkstra3d.parental_field(PDRF, root)
del PDRF
else:
parents = PDRF

if soma_mode:
invalidated, labels = kimimaro.skeletontricks.roll_invalidation_ball(
labels, DBF, np.array([root], dtype=np.uint32),
scale=soma_invalidation_scale,
const=soma_invalidation_const,
anisotropy=anisotropy
)

paths = compute_paths(
root, labels, DBF, DAF,
parents, scale, const, anisotropy,

## dijkstra3d

Implementation of Dijkstra's Shortest Path algorithm on 3D images. GitHub GPL-3.0 Latest version published 3 days ago

72 / 100

## Popular Python code snippets

Find secure code to use in your application or website