You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two errors above are for all zeros, and an array with only isolated points.
The final call has two [ 0. 0. ] coords. At least 1 [0. 0.] is always present
The coords are all floating point and must be cast to integers for indexing
To fix it, I wrapped it like:
def get_cs_graph(skeleton: numpy.ndarray):
"""
Get compressed sparse adjacency matrix of a skeleton
:param skeleton: a skeletonized image
:return: adj:csv_matrix, nonzero_pixel_coords: ndarray, degree_mask:ndarray
"""
# Skan: https://jni.github.io/skan/getting_started.html
# Skan, the source of 'skeleton_to_csgraph' always returns the origin in the pixel list, even if the
# matrix is mostly zeros, so calculate this component with numpy
coords = numpy.vstack(numpy.where(skeleton > 0)).T
# Skan yields errors under some numerical conditions related to all zero arrays, and arrays with isolated pixels
try:
adj, _, degrees = skeleton_to_csgraph(skeleton)
except ValueError as e:
warnings.warn(str(e))
adj = csr_matrix()
degrees = numpy.zeros_like(skeleton)
return adj, coords, degrees
The text was updated successfully, but these errors were encountered:
Thanks for raising @chrisdonlan! It's definitely a trip wire and you're not the first to raise it (see #107 and #93). I might be able to set some time aside next week to address this. I think the ideal fix is to add a layer of indirection between the pixel ids and the coordinates array.
Note that the float coordinates are by design, because some junction pixels get collapsed to their centroid. Perhaps a utility function that does tuple(np.round(coords).astype(int))) would be a useful addition also. It might even belong in scikit-image itself.
Perhaps this is not a bug. However, it was a trip wire.
This issue summarizes as:
To fix it, I wrapped it like:
The text was updated successfully, but these errors were encountered: