This sounds easy (in which case I will delete my question) and maybe I am getting a bit tired, but I can't find an easy way to create a list from an automatically-generated graph where vertices labels and coordinates are associated, e.g. {index_vertex, {x,y}}.

From this image...

enter image description here

...here is my code so far:

image = Import["https://i.sstatic.net/5ZNrE.png"];
mask = FillingTransform[Thinning[Binarize[ColorReplace[image, White -> Black, .055], 0]], CornerNeighbors -> True];
skel = Thinning[mask];
morphograph = MorphologicalGraph[skel, VertexSize -> 2, VertexLabels -> "Index"];
newtreegraph = TreeGraph[DeleteCases[EdgeList[morphograph], x_ [UndirectedEdge] x_], VertexCoordinates -> GraphEmbedding[morphograph], VertexSize -> 5, VertexLabels -> "Index"]

that generates this nice TreeGraph

enter image description here

From that, I can obtain the EdgeList and vertices coordinates via GraphEmbedding but cannot easily connect the two... There must be an easy way I can't find ... Thanks


1 Answer 1


Do you mean this?

 PropertyValue[newtreegraph, VertexCoordinates]

<|1 -> {677.5, 957.5}, 8 -> {677.5, 953.5}, <<459>>, 455 -> {300.5, 84.5}|>

  • 2
    $\begingroup$ Instead of PropertyValue[newtreegraph, VertexCoordinates] you can also use GraphEmbedding[newtreegraph]. $\endgroup$
    – Szabolcs
    Feb 21, 2019 at 16:29
  • $\begingroup$ Yes thanks! That was indeed pretty easy... $\endgroup$
    – Valacar
    Feb 21, 2019 at 21:28
  • 1
    $\begingroup$ You're welcome! Might seem easy (afterwards), but this was also a question worthwhile to ask (+1). $\endgroup$ Feb 21, 2019 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.