3
$\begingroup$

I would like to ask for suggestions on how to obtain the thickness of the edges in a given input image

Input image:

enter image description here

I tried to follow the commands given in a similar question posted, How to determine edgeweights from width of skeleton using MorphologicalGraph (or workaround)?

img = Import["https://i.sstatic.net/Ww0td.png"]
g = MorphologicalGraph[img, EdgeWeight -> Automatic];
weights = OptionValue[Options[g, EdgeWeight], EdgeWeight]
vertices = VertexList[g];
crds = OptionValue[Options[g, VertexCoordinates], VertexCoordinates];
edges = List @@@ EdgeList[g];

GraphPlot[Rule @@@ edges,
  VertexCoordinates -> Thread[vertices -> crds],
  EdgeRenderingFunction -> (With[{w = 
        Pick[Rescale[weights], edges, (#2 | Reverse[#2])][[1]]},
      {Thickness[.02 (.1 + w)],
       ColorData["SunsetColors"][.9 w], Line[#1]}] &), 
  AspectRatio -> 1]

However, the output is the following:

enter image description here

I'm not sure how to proceed. Any suggestions will be really helpful. In the output I would like to obtain the thickness of edge and corresponding edge indices.

Source of image: ref

Also sharing the link of crosspost here.

$\endgroup$
9
  • 1
    $\begingroup$ Could you please let us know where your source image is from? It is very familiar. $\endgroup$
    – Szabolcs
    Commented Apr 30, 2020 at 17:25
  • $\begingroup$ I am sure someone will post an answer that will work for at least this sample image, but when I needed to do this last time, I gave up on Mathematica and used Fiji instead, which is able to extract the pixel intensities for each segment. We can use something like SkeletonTransform or DistanceTransform to convert thickness into intensity. For this reason, I did suggest to Wolfram to make MorphologicalGraph capable not only of recording the number of pixels in each segment, but also the pixel intensities. $\endgroup$
    – Szabolcs
    Commented Apr 30, 2020 at 17:31
  • 1
    $\begingroup$ maybe the following could be staring point? mathematica.stackexchange.com/questions/192177/… $\endgroup$
    – halmir
    Commented Apr 30, 2020 at 17:32
  • $\begingroup$ The idea with SkeletonTransform is something like this: ImageAdjust@Pruning@Pruning@SkeletonTransform[img]. This way thicknesses are changed to intensities. One problem is that SkeletonTransform does not produce the same kind of skeleton as Thinning, which would be much nicer (fewer "outgrowths") $\endgroup$
    – Szabolcs
    Commented Apr 30, 2020 at 17:34
  • 1
    $\begingroup$ This is the tool in Fiji: imagej.net/AnalyzeSkeleton And something similar to your application was why I tried to much to use Fiji directly from Mathematica (but then gave up on that too). mathematica.stackexchange.com/q/180513/12 $\endgroup$
    – Szabolcs
    Commented Apr 30, 2020 at 17:42

0

Your Answer

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