0

I'd like to get a measure of the thickness of branches in an image. The following is the output obtained from Fiji.

enter image description here

I'd like to compute an average measure of the thickness associated with each edge. By edge, I mean the segment present between any two branching points.

Any directions on how to proceed will be really helpful.

Image source: ref

EDIT: Node is a junction point or the terminal points. Please let me know if it is not clear and if I have to explain it further. For instance, if we skeletonize the above image like the ones shown here, the junctions or terminal points will be nodes. If it helps, I can share a skeletonized version of the above image.

EDIT2: enter image description here

{1 -> {36.4156, 23.8112, 0.},
 2 -> {83.4779, 151.809, 0.}, 
 3 -> {182.451, 145.504, 0.},
 4 -> {227.385, 86.2469, 0.}, 
 5 -> {311.9, 218.811, 0.},
 6 -> {483.204, 190.795, 0.}, 
 7 -> {601.916, 226.427, 0.},
 8 -> {780.405, 312.889, 0.}, 
 9 -> {974.959, 274.093, 0.},
 10 -> {656.313, 209.944, 0.}, 
 11 -> {815.08, 182.186, 0.},
 12 -> {923.162, 121.453, 0.}, 
 13 -> {353.554, 34.5667, 0.},
 14 -> {479.314, 87.3631, 0.}, 
 15 -> {662.5, 119.5, 0.},
 16 -> {759.72, 99.8905, 0.}, 
 17 -> {539.501, 34.4999, 0.},
 18 -> {712.917, 26.8174, 0.}, 
 19 -> {896.5, 65.5, 0.},
 20 -> {143.654, 379.583, 0.}, 
 21 -> {203.382, 270.926, 0.},
 22 -> {311.084, 354.623, 0.}, 
 23 -> {495.5, 330.5, 0.},
 24 -> {643.872, 319.37, 0.}, 
 25 -> {794.571, 405.533, 0.},
 26 -> {415.864, 397.252, 0.}, 
 27 -> {624.794, 369.389, 0.},
 28 -> {488.5, 276.5, 0.}}
Natasha
  • 1,111
  • 5
  • 28
  • 66

1 Answers1

1

You can do distance transform. Multiply the resulting image by the skeleton. See an example. Decomposition the skeleton into segments and average over the segments. This will be the average line thickness. Matlab/Octave code:

a=imread('IW.png');
bw=im2bw(a, 0.1);
skeleton=bwmorph(bw, 'skel', Inf);
D = bwdist(~bw);
imagesc(D.*single(skeleton));

enter image description here

Or this Matlab/Octave code:

a=imread('IW.png');
bw=im2bw(a, 0.1);
skeleton=bwmorph(bw, 'skel', Inf);
branchpoints=bwmorph(skeleton, 'branchpoints');
se=strel('disk', 3);
branchpoints=imdilate(branchpoints,se);
segments=skeleton>branchpoints;
segments=bwareaopen(segments, 8);
stats = regionprops(segments,'Centroid', 'PixelIdxList');
centroids = cat(1, stats.Centroid);
D = bwdist(~bw);
hold on
%imagesc(D.*single(skeleton))
imshow(a)
for i=1:numel(stats)
    m(i)=mean(D(stats(i).PixelIdxList));
    text(centroids(i,1),centroids(i,2), num2str(m(i)), 'Color','blue');
end

Result: enter image description here

Alex Alex
  • 1,893
  • 1
  • 6
  • 12
  • Thank you. What I am looking for is an average value of color/ the predominant color of each branch (a branch is a segment between two junctions). In the end, I'd like to assign a single value fo color to each branch. If my understanding is right, the image posted above has this already. Can we translate this result into a table with edge labels( for example edge 1-2 colorcode 6.5) and colors? – Natasha May 03 '20 at 15:52
  • First you need to cut the skeleton into segments. This can be done with the XOR operation (skeleton, 'branchpoints' ). Then you need to go through the connected components and calculate the average for the segment. – Alex Alex May 03 '20 at 16:11
  • Thanks a lot for the tip. Could you please offer some suggestions on how to do this `First you need to cut the skeleton into segments`? – Natasha May 03 '20 at 16:27
  • Thank you. For some reason, when I run the above code in 2019b, I find only a black and white image with text displayed on it. Are you using 2020a? If yes, could you please let me know how to get the same output as shown above in 2019b? – Natasha May 04 '20 at 03:05
  • Version 2017b. You change first line? File name is correct? Start on step by step debug mode. – Alex Alex May 04 '20 at 03:32
  • Ok. Yes, I've changed the file name. I suppose you are using the first image shared by me as the original input. – Natasha May 04 '20 at 03:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/213057/discussion-between-alex-alex-and-natasha). – Alex Alex May 04 '20 at 03:35
  • Hi, I tried the code that was shared in the discussion chat on a new image (thickness map from Fiji ([image](https://github.com/DeepaMahm/misc/blob/master/Fig4a_thickness.png)), skeleton generated from Fiji ([image](https://github.com/DeepaMahm/misc/blob/master/Fig4a_skeleton.png)) using this code ([MATLAB code](https://github.com/DeepaMahm/misc/blob/master/thickness_measurement.m)). The values are not displayed on each branch of the network after running the MATLAB code. Could you please have a look? – Natasha Jan 31 '22 at 06:15