0
$\begingroup$

I'm using MorphologicalGraph to convert images to graph. This is my source image:This is my source image

Following this and this, I tried

i = Thinning[Binarize@Import["https://i.stack.imgur.com/WfVsG.png"],
    3, Method -> "MedialAxis"];
g = MorphologicalGraph[i, 
   EdgeStyle -> Directive[Orange, Opacity[.5], Thickness[.01]], 
   GraphStyle -> "ThickEdge"];
Show[Dilation[i, 1], g]

Below is the output, some edges are not detected while some are detected wronglyoutput.

Could anyone help me with this? Is this caused by the image quality?

$\endgroup$
4
  • $\begingroup$ Try converting the image to grayscale, then dilate, binarize and thin i.e. ColorConvert[i,"Grayscale"]//Dilation[#,1]&//Thinning then try MorphologicalGraph. BTW you've got two graphs in the image - the outer box and the inner more connected object $\endgroup$
    – EstabanW
    Jul 10 '21 at 10:02
  • 2
    $\begingroup$ For MorphologicalGraph, a "vertex" is a branching point. The "corner" in the lower left of the image is not a branching point, so it will not be a vertex in the result. This is not incorrect behaviour. If you want that point detected, as a first step you would need to come up with a clear definition of what you consider a vertex. $\endgroup$
    – Szabolcs
    Jul 10 '21 at 10:55
  • 2
    $\begingroup$ The other issue is that MorphologicalGraph does not support multi-edges at this point. This is an unfortunate limitation. I have requested this feature from Wolfram multiple times. They are more likely to add it if more people request it. $\endgroup$
    – Szabolcs
    Jul 10 '21 at 10:55
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Jul 10 '21 at 15:05

Your Answer

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

Browse other questions tagged or ask your own question.