# Compute thickness of branches in a 2D image

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

Input image:

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

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.

• Could you please let us know where your source image is from? It is very familiar. Apr 30, 2020 at 17:25
• 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. Apr 30, 2020 at 17:31
• maybe the following could be staring point? mathematica.stackexchange.com/questions/192177/… Apr 30, 2020 at 17:32
• 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") Apr 30, 2020 at 17:34
• 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 Apr 30, 2020 at 17:42