Update 06 /11 /2014
The ipython notebook from the previous post was rewritten . A python function building a graph from a skeleton was modified to generate a multigraph (networkx). This function (available in an ipython notebook) is used as follow:
- Graph : a networkx multigraph object.
- skeleton : the binary image of skeleton obtained by morphological thining with mahotas.
image_test= makeLetterImage('a', 75)
skeleton_test = mh.thin(image_test)
Ep_Ep = skeleton_test*np.logical_not(Ep)
Ep_Ep,_ = mh.label(Ep,Ep)
l_Ep, _ = mh.label(Ep)
Graph_test = nx.MultiGraph()
!neato -T png multi.dot > multi.png
The skeleton has two edges, linking the same branched points (yellow and red pixels). The graph was exported to build an image of the multigraph (middle), networkx doesn't seem to be capable to dispolay correctly such multigraph (right)
When applied to a lowercase alphabet:
The function produced the corresponding graphs (the letter 'o' excepted):
imTest = makeLetterImage('b', 70)
skelTest = mh.thin(imTest)
Ep_Bp, Bp_Bp, Bp, Ep = SkeletonDecomposition(skelTest)
- skeltest: the image skeleton obtained by thining with mahotas.
- Bp : image of branched-point(s)
- Ep: image of end-point(s)
- Bp_Bp :edge(s) between branched-points
- Ep_Bp:edge(s) between end-point(s) and branched-point(s)
An other graph library: Graph-tool
The graphic representation of a multigraph produced by graphtool is so nice that it may worth to learn the graphtool syntax to make a graph: