Compute thickness of branches in a 2D image

Hi All,

This is a follow up to my previous question posted here that was about skeletonizing a 2D image (notebook is also available here).

This was the input image used. I would like to ask for suggestions on how to obtain the thickness of the edges in this input image.

I tried the following to obtain thickness as edge weights

img = input image
gray = ImagePad[ImageCrop[ColorConvert[img, "Grayscale"], ImageDimensions[img] - 6],10]
bin = Binarize[gray, 0.07]
g = MorphologicalGraph[bin, EdgeWeight -> Automatic];
weights = OptionValue[Options[g, EdgeWeight], EdgeWeight]

But from what I read in a discussion thread, EdgeWeight → Automatic sets edge lengths as edge weights.

So I tried what has been suggested here

vertices = VertexList[g];
crds = OptionValue[Options[g, VertexCoordinates], VertexCoordinates];
edges = List @@@ EdgeList[g];

GraphPlot[Rule @@@ edges,
  VertexCoordinateRules -> 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]

The output doesn’t appear to be right,

Any suggestions will be helpful

Many thanks

The MSE post you are using is very old. Options VertexLabeling and VertexCoordinateRules have been superseded in V12. That is why they are highlighted red in the notebook. You will have to change the code to use the new options. e.g. see VertexCoordinateRules

Hi,

Thanks a lot for the response. I had a look at the link that you shared, but unfortunately I don’t clearly understand how the VertexCoordinateRules have to be modified.

At the top of the page for that link

As of Version 12.0, VertexCoordinateRules has been superseded by
VertexCoordinates.

Compare the documentation for the deprecated VertexCoordinateRules (from the link) with the documentation for VertexCoordinates.

I get the same output even after using

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]

Same issue EdgeRenderingFunction is not an option for GraphPlot. Make sure none of the options are highlighted in red in the notebook.

Crossposted here.