How to extract skimage skeleton information to NetworkX nodes and edges in python for further advanced analysis

强颜欢笑 提交于 2019-12-07 15:46:46

问题


Currently, I use skimage in python to extract the skeleton of open space from some a binarized map as following pictures,

With following python codes:

from skimage.morphology import skeletonize
from skimage import draw
from skimage.io import imread, imshow
from skimage.color import rgb2gray

# load image from file
img_fname=os.path.join('images','mall1_2F_schema.png') 
image=imread(img_fname)

# Change RGB color to gray 
image=rgb2gray(image)

# Change gray image to binary
image=np.where(image>np.mean(image),1.0,0.0)

# perform skeletonization
skeleton = skeletonize(image)

Now I would like to extract the end points and cross points from the skeleton as nodes for Networkx graph object while calculating the distance between the neighboring nodes as edges for Networkx Graph object. Currently, I have to manually get the point coordinates and input to NetworkX object initialization process, do we have any smarter way to do everything automatically?

By the way, I found yaron kahanovitch's answer to the question on stackoverflow proposes similar approaches. However, no more realization suggestions was given, and I think NetworkX could be one approach.

Any suggestions from you are greatly appreciated.

来源:https://stackoverflow.com/questions/41008973/how-to-extract-skimage-skeleton-information-to-networkx-nodes-and-edges-in-pytho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!