I checked the documentation.
I could obtain the edges,
[(0, 1, 0), (0, 1, 1), (0, 1, 2), (2, 4, 0), (2, 12, 0), (2, 8, 0), (3, 5, 0), (3, 4, 0), (3, 4, 1), (5, 18, 0), (5, 11, 0), (6, 11, 0), (6, 7, 0), (6, 7, 1), (7, 8, 0), (8, 10, 0), (9, 13, 0), (9, 12, 0), (9, 14, 0), (10, 11, 0), (10, 13, 0), (12, 20, 0), (13, 16, 0), (14, 24, 0), (14, 17, 0), (15, 19, 0), (15, 16, 0), (15, 16, 1), (17, 22, 0), (17, 20, 0), (18, 19, 0), (18, 29, 0), (19, 24, 0), (20, 25, 0), (21, 23, 0), (21, 23, 1), (21, 22, 0), (22, 27, 0), (23, 26, 0), (24, 26, 0), (25, 25, 0), (26, 28, 0), (27, 28, 0), (27, 28, 1)]

I could exactly understand this,
graph.edge(id1, id2)[0] 

For a simple graph,

for (s,e) in graph.edges():
    ps = graph[s][e]['pts']
    plt.plot(ps[:,1], ps[:,0], 'green')

the above works.

Could you please suggest how the above loop has to be modified to obtain the positions of multi-edges?

Thanks a  lot,
Deepa 

On Fri, Nov 30, 2018 at 6:10 PM <imagepy@sina.com> wrote:
Please see sknw's document on github's read me. the default multi = False
and if it's a multigraph, you must add a index after two node id to get the edge, like: graph.edge(id1, id2)[0]
graph = sknw.build_sknw(ske, multi=False)

ske: should be a nd skeleton image

multi: if True,a multigraph is retured, which allows more than one edge between two nodes and self-self edge. default is False.

return: is a networkx Graph object

----- 原始邮件 -----
发件人:Deepa <deepamahm.iisc@gmail.com>
收件人:imagepy@sina.com, scikit-image@python.org
主题:Re: [scikit-image] 回复:Re: Converting an image to a skeleton
日期:2018年11月30日 17点36分

I checked the sknw package .
I'm using the input matrix data of the skeleton image that is created using Mathematica.
Here is my code that is written to highlight all the nodes and edges

from skimage.morphology import skeletonize
from skimage import data
import sknw
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as spio
import networkx as nx
from networkx.drawing.nx_pydot import write_dot
mat = spio.loadmat('file.mat', squeeze_me=True)
print(type(mat))
print(type(mat.get('Expression1')))
print(mat.get('Expression1'))
img1 = mat.get('Expression1')
print(img1)
ske = skeletonize(img1).astype(np.uint16)
# build graph from skeleton
graph = sknw.build_sknw(ske)

# draw image
plt.imshow(img1, cmap='gray')

# draw edges by pts
for (s,e) in graph.edges():
    ps = graph[s][e]['pts']
    plt.plot(ps[:,1], ps[:,0], 'green')

# draw node by o
node, nodes = graph.node, graph.nodes()
ps = np.array([node[i]['o'] for i in nodes])
plt.plot(ps[:,1], ps[:,0], 'r.')
#pos = nx.nx_agraph.graphviz_layout(graph)
#print(pos)
#plt.findpath(img1)
# title and show
plt.title('Build Graph')
plt.show()

Please find the input  file.mat file here. Even with sknw package I face the same problem when there are multiple edges.Please the output image attached. Some edges are not highlighted in green.

Could you please suggest how this can be improved?

On Thu, Nov 29, 2018 at 7:33 PM <imagepy@sina.com> wrote:
please see my mail earlier,skan and sknw on github.


----- 原始邮件 -----
发件人: Leena Chourey<leenagour@gmail.com>
收件人: Mailing list for scikit-image (http://scikit-image.org)<scikit-image@python.org>
主题: [scikit-image] Re: Converting an image to a skeleton
日期: 2018-11-29 19:40

I need solution for same. Pls share.

On Thu, 29 Nov 2018, 16:37 Deepa, <deepamahm.iisc@gmail.com> wrote:

I would like to generate a skeleton out of an image. The resulting output of the skeleton image has disconnected edges. 

import skimage
from skimage import data,io,filters
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage.filters import threshold_adaptive,threshold_mean
from skimage.morphology import binary_dilation
from skimage import feature
from skimage.morphology import skeletonize_3d

imgfile = "Bagah.jpeg"
im = cv2.imread(imgfile)
image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
thresh = threshold_mean(image)
thresh = threshold_mean(thresh)

binary = image > thresh
#dilate = skimage.morphology.binary_dilation(binary)
gaussian = skimage.filters.gaussian(binary)
edges = filters.sobel(gaussian)
#dilate = feature.canny(edges)#binary,sigma=0)
skeleton = skeletonize_3d(gaussian)#binary)
fig, axes = plt.subplots(nrows=2,ncols=2, figsize=(8, 2))

ax = axes.ravel()
ax[0].imshow(gaussian, cmap=plt.cm.gray)

ax[0].set_title('gaussian')

ax[1].imshow(skeleton, cmap=plt.cm.gray)
ax[1].set_title('skeleton')

for a in ax:
 a.axis('off')

plt.show()

Please find the attachments of my input and output files.
I would like to translate this skeleton into a graph with nodes and edges.

Could someone suggest how to obtain a skeleton with connected edges?

I’m protected online with Avast Free Antivirus. Get it here — it’s free forever.

_______________________________________________
 scikit-image mailing list -- scikit-image@python.org
 To unsubscribe send an email to scikit-image-leave@python.org

_______________________________________________
scikit-image mailing list -- scikit-image@python.org
To unsubscribe send an email to scikit-image-leave@python.org

来自新浪邮箱触屏版

_______________________________________________
scikit-image mailing list -- scikit-image@python.org
To unsubscribe send an email to scikit-image-leave@python.org