Message Boards Message Boards

0
|
4049 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Compute thickness of branches in a 2D image

Posted 4 years ago

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,

enter image description here

Any suggestions will be helpful

Many thanks

POSTED BY: Natash A
6 Replies
Posted 4 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Posted 4 years ago

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

POSTED BY: Rohit Namjoshi
Posted 4 years ago

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.

POSTED BY: Rohit Namjoshi
Posted 4 years ago

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]

POSTED BY: Natash A
Posted 4 years ago

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

POSTED BY: Rohit Namjoshi
Posted 4 years ago

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.

POSTED BY: Natash A
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract