我正在使用骨架到csgraph()来分析我已经获得的骨架,这个函数应该向我返回一些数据,其中包括矩阵(N+1)中所有骨架的点的坐标(N+1)x 2,其中N是点数。然而,在一种情况下,这个函数会无缘无故地给我一个坐标矩阵,但有一些错误。有人知道错误可能来自哪里吗?
有关该函数和包的更多信息,请单击此处:https://jni.github.io/skan/
使用栅格时,值为1或0的int32 200,100的ndarray。此链接中的文件:https://drive.google.com/drive/folders/12xwZBv3RKQ4Q802jXPAhtYZXHrsMytMl?usp=sharing
skeleton, distance = medial_axis(grid, return_distance=True)
graph, coordinates, degrees = skeleton_to_csgraph(skeleton)如图所示,对于一个坐标,我得到的不是整数值
发布于 2021-05-14 09:22:30
您遇到的问题是因为skan需要将结点像素折叠到它们的质心中,以便生成连贯的图形。详情请参见https://doi.org/10.7717/peerj.4312/supp-2。很抱歉,这没有更好的文档。我已经提出了一个问题,以在未来改进这一点:
https://github.com/jni/skan/issues/121
这个问题也是相关的:坐标数组包含所有节点坐标,但也包含一些垃圾坐标:
https://github.com/jni/skan/issues/108
欢迎在github上继续讨论!?
发布于 2021-05-09 21:09:18
下面的步骤如下:注意:我是在jupyter笔记本上运行的,你会看到的!在安装开始时
!pip install git+https://github.com/jni/skan # install latest version github加载数据,并处理它。
import numpy as np
from skimage.morphology import medial_axis
from skan import skeleton_to_csgraph
from skan import _testdata
from skan import draw
from matplotlib import pyplot as plt
grid = np.load('grid.npy') # this is the file you shared through google drive
skeleton, distance = medial_axis(grid, return_distance=True)
graph, coordinates, degrees = skeleton_to_csgraph(skeleton)
fig, ax = plt.subplots()
draw.overlay_skeleton_networkx(graph,coordinates, image=skeleton,axis=ax)
fig, ax = plt.subplots()
draw.overlay_skeleton_2d(grid, skeleton, dilate=1, axes=ax);

发布于 2021-05-11 19:29:39
在某些特定情况下,函数skeleton-to-csgraph()似乎存在问题。但是为了克服这个错误,下面的代码提供了您应该得到的结果:
a = np.where(skeleton == 1 )
b = np.array([a[0], a[1]]).transpose()
coordinates = np.vstack(([0,0],b))对于骨架,包含骨架图像和坐标的numpy数组,这是您应该使用skeleton-to-csgraph()获得的结果,其中包含骨架点的所有坐标。
https://stackoverflow.com/questions/67432801
复制相似问题