Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have an image which looks like

from How to convert an image to a graph and get the positions of the edges?

which by using MorphologicalGraph becomes a graph that is a collections of polygons:

i = Import["http://i.stack.imgur.com/cET4A.png"];
g = MorphologicalGraph[i, 
     EdgeStyle -> Directive[Orange, Opacity[.5], Thickness[.01]],
     GraphStyle -> "ThickEdge"];
Show[ColorNegate@Dilation[i, 1], g]

I am wondering if, for each polygon, it is possible to extract the number of edges?

share|improve this question
add comment

2 Answers

There are some stray lines in the image which may be difficult to handle. You can remove these using Pruning. Use MorphologicalGraph after this. Now your problem is reduced to finding the faces of the planar graph you obtained. You'll find complete code for that in the answer to this question:

share|improve this answer
add comment

You have a few lines pointing out here and there, suggesting that it's actually only lines, not polygons.

coords = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates];
con = (ArrayRules@AdjacencyMatrix[g])[[1 ;; -2, 1]];
Graphics@GraphicsComplex[coords, Line[Union[Sort /@ con]]]

lines

If you right click your original graph and Convert to Graphics that is also composed of Lines and a bit of styling.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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