Search code examples
pythoncoordinateserror-reporting

Error with coordinates of skeleton_to_csgraph (python)


I am using skeleton-to-csgraph() to analyse the skeleton I have obtained and this function should send me back some data and among them, all the coordinates of all the points of the skeleton in a matrix [(N+1) x 2] with N the number of points. However there is one situation where this function gives me a coordinates matrix with some error for no reasons. Does someone knows from where the error could come from ?

More information about the function and the package here: https://jni.github.io/skan/

Lines of the coordinates matrix given by skeleton-to-csgraph function. At the line 326 an unexplained error, it should be an int and not a float value because it is a pixel index

with grid, a ndarray of int32 [200,100] with value of 1 or 0. File in this link: https://drive.google.com/drive/folders/12xwZBv3RKQ4Q802jXPAhtYZXHrsMytMl?usp=sharing

skeleton, distance = medial_axis(grid, return_distance=True)
graph, coordinates, degrees = skeleton_to_csgraph(skeleton)

Like on the picture, I obtained none integer value for one coordinate


Solution

  • The issue you're encountering is because skan needs to collapse junction pixels into their centroid in order to produce a coherent graph. See https://doi.org/10.7717/peerj.4312/supp-2 for details. Apologies that this is not better documented. I've made an issue to improve this in the future:

    https://github.com/jni/skan/issues/121

    This issue is also related: the coordinates array contains all node coordinates but also some junk coordinates:

    https://github.com/jni/skan/issues/108

    Feel free to continue the discussion on github! 🙏