首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >skeleton_to_csgraph (python)的坐标错误

skeleton_to_csgraph (python)的坐标错误
EN

Stack Overflow用户
提问于 2021-05-07 18:01:06
回答 3查看 97关注 0票数 0

我正在使用骨架到csgraph()来分析我已经获得的骨架,这个函数应该向我返回一些数据,其中包括矩阵(N+1)中所有骨架的点的坐标(N+1)x 2,其中N是点数。然而,在一种情况下,这个函数会无缘无故地给我一个坐标矩阵,但有一些错误。有人知道错误可能来自哪里吗?

有关该函数和包的更多信息,请单击此处: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

使用栅格时,值为1或0的int32 200,100的ndarray。此链接中的文件:https://drive.google.com/drive/folders/12xwZBv3RKQ4Q802jXPAhtYZXHrsMytMl?usp=sharing

代码语言:javascript
复制
skeleton, distance = medial_axis(grid, return_distance=True)
graph, coordinates, degrees = skeleton_to_csgraph(skeleton)

如图所示,对于一个坐标,我得到的不是整数值

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 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上继续讨论!?

票数 0
EN

Stack Overflow用户

发布于 2021-05-09 21:09:18

下面的步骤如下:注意:我是在jupyter笔记本上运行的,你会看到的!在安装开始时

代码语言:javascript
复制
!pip install git+https://github.com/jni/skan # install latest version github

加载数据,并处理它。

代码语言:javascript
复制
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);

Complete code screen snap

票数 0
EN

Stack Overflow用户

发布于 2021-05-11 19:29:39

在某些特定情况下,函数skeleton-to-csgraph()似乎存在问题。但是为了克服这个错误,下面的代码提供了您应该得到的结果:

代码语言:javascript
复制
a = np.where(skeleton == 1 )
b = np.array([a[0], a[1]]).transpose()
coordinates = np.vstack(([0,0],b))

对于骨架,包含骨架图像和坐标的numpy数组,这是您应该使用skeleton-to-csgraph()获得的结果,其中包含骨架点的所有坐标。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67432801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档