Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using Mathematica 8, I created a morphological graph from the list of white pixels in the image. It is working fine on your first image:</p> <p><img src="https://i.stack.imgur.com/rAW9V.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/RiNTM.png" alt="enter image description here"></p> <p>Create the morphological graph:</p> <pre><code>graph = MorphologicalGraph[binaryimage]; </code></pre> <p>Then you can query the graph properties that are of interest to you.</p> <p>This gives the names of the vertex in the graph:</p> <pre><code>vertex = VertexList[graph] </code></pre> <p>The list of the edges:</p> <pre><code>EdgeList[graph] </code></pre> <p>And that gives the positions of the vertex:</p> <pre><code>pos = PropertyValue[{graph, #}, VertexCoordinates] &amp; /@ vertex </code></pre> <p>This is what the results look like for the first image:</p> <pre><code>In[21]:= vertex = VertexList[graph] Out[21]= {1, 3, 2, 4, 5, 6, 7, 9, 8, 10} In[22]:= EdgeList[graph] Out[22]= {1 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 5, 4 \[UndirectedEdge] 6, 6 \[UndirectedEdge] 7, 6 \[UndirectedEdge] 9, 8 \[UndirectedEdge] 9, 9 \[UndirectedEdge] 10} In[26]:= pos = PropertyValue[{graph, #}, VertexCoordinates] &amp; /@ vertex Out[26]= {{54.5, 191.5}, {98.5, 149.5}, {42.5, 185.5}, {91.5, 138.5}, {132.5, 119.5}, {157.5, 72.5}, {168.5, 65.5}, {125.5, 52.5}, {114.5, 53.5}, {120.5, 29.5}} </code></pre> <p>Given the documentation, <a href="http://reference.wolfram.com/mathematica/ref/MorphologicalGraph.html" rel="noreferrer">http://reference.wolfram.com/mathematica/ref/MorphologicalGraph.html</a>, the command MorphologicalGraph first computes the skeleton by morphological thinning:</p> <pre><code>skeleton = Thinning[binaryimage, Method -&gt; "Morphological"] </code></pre> <p>Then the vertex are detected; they are the branch points and the end points:</p> <pre><code>verteximage = ImageAdd[ MorphologicalTransform[skeleton, "SkeletonEndPoints"], MorphologicalTransform[skeleton, "SkeletonBranchPoints"]] </code></pre> <p><img src="https://i.stack.imgur.com/KbITD.png" alt="enter image description here"></p> <p>And then the vertex are linked after analysis of their connectivity.</p> <p>For example, one could start by breaking the structure around the vertex and then look for the connected components, revealing the edges of the graph:</p> <pre><code>comp = MorphologicalComponents[ ImageSubtract[ skeleton, Dilation[vertices, CrossMatrix[1]]]]; Colorize[comp] </code></pre> <p><img src="https://i.stack.imgur.com/E6B9K.png" alt="enter image description here"></p> <p>The devil is in the details, but that sounds like a solid starting point if you wish to develop your own implementation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload