4
$\begingroup$

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.stack.imgur.com/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

$\endgroup$
7
$\begingroup$

Do you mean this?

AssociationThread[
 VertexList[newtreegraph],
 PropertyValue[newtreegraph, VertexCoordinates]
 ]

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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