Exercise: measuring neurons and vessel networks
Before this unit: From skeleton to graph: pruning and length (previous unit); The Hessian: blobs, ridges and saddles (day 2); Day 14: Labelling; Day 2: Edges, blobs and ridges.
See also: Day 15: Watershed; Day 16: Measurements.
Goal
By the end of this exercise you should be able to:
- compute the standard neuron measurements from a skeleton graph: total length, branch and terminal points, Strahler order, a Sholl profile,
- compute the standard vessel measurements: length and branching density, radius from the distance transform, tortuosity,
- compare a measured graph with a true one: missed and spurious branch points,
- predict how the failure modes of the vesselness filter show up in the graph,
- (math) use Murray’s law and the tortuosity of an arc.
Do the pen-and-paper part first, then the demo.
Background
| Idea | What it means |
|---|---|
| Pipeline | vesselness (edges day) → hysteresis threshold → clean → skeleton → prune → graph |
| Total length | sum of the edge lengths |
| Strahler order | tips: 1; at a branch point, if the two child branches have the same order s, the parent has s + 1, otherwise the larger order |
| Sholl profile | N(r) = number of crossings of the arbor with the circle of radius r around the soma |
| Radius | \mathrm{DT} on the skeleton; diameter 2\,\mathrm{DT} |
| Tortuosity | path length / chord of an edge (1 = straight) |
| Densities | total length / area; branch points / area |
| Matching | a true and a measured branch point match if they are within a distance d (each used once, closest pairs first); unmatched true = missed, unmatched measured = spurious |
By hand
B1. A traced neuron: soma S (radius 8 µm), branch points a and d, tips b, c, e, f. Each edge runs outwards, so its distance from the soma centre grows along it from r_\text{in} to r_\text{out}.
| edge | length (µm) | chord (µm) | r_\text{in} | r_\text{out} |
|---|---|---|---|---|
| S–a | 30 | 28 | 8 | 36 |
| a–c | 40 | 32 | 36 | 70 |
| a–d | 25 | 24 | 36 | 60 |
| d–e | 20 | 19 | 60 | 78 |
| d–f | 35 | 25 | 60 | 90 |
| S–b | 50 | 45 | 8 | 55 |
- Total dendritic length, number of primary branches, branch points and terminal points.
- The tortuosity of each edge, and the mean. Which edge is the most tortuous?
- The Strahler order of every edge. And the centrifugal order?
- The Sholl counts N(r) for r = 20, 50, 65 and 80 µm. Sketch the profile.
B2. Along a vessel centreline the distance transform reads 3.0, 3.2, 3.6, 3.6, 3.2 (pixels). (a) Mean radius and diameter? (b) The best vesselness scale on this vessel is σ = 4.5. On the edges day, a line with a Gaussian profile of width s gave its strongest response at \sigma = \sqrt2\,s. What width does that suggest, and does it agree with (a)? (c) The threshold of the vesselness is lowered. What happens to the mask, to \mathrm{DT} on the skeleton and to the radius estimate? And to the skeleton itself?
B3. True branch points at (20, 30), (45, 32), (60, 70), (80, 40), (95, 90); measured ones at (22, 31), (47, 36), (81, 43), (70, 75), (95, 92), (30, 80) (pixels). Match within 5 pixels. (a) Which pairs match? How many branch points are missed, how many spurious? (b) Precision (matched / measured) and recall (matched / true)? (c) (60, 70) and (70, 75) are 11.2 pixels apart. What might have happened there?
B4. Predict how each problem shows up in the skeleton graph (branch points, end points, edges, length): (a) the vesselness fades where two vessels branch; (b) two vessels run side by side, touching; (c) bright cells sit on a vessel; (d) the noise is high and pruning is off.
B5. A vessel image of 256 × 256 pixels with 2 µm pixels has a total corrected length of 1109 pixels and 12 branch points. (a) The image area in mm², the total length in mm, the length density in mm/mm² and the branching density per mm². (b) Why should densities in physical units, not counts in pixels, be compared between images of different size or pixel size?
B1. (a) Total length 30 + 40 + 25 + 20 + 35 + 50 = 200 µm. Primary branches: 2 (S–a, S–b). Branch points: 2 (a, d). Terminal points: 4 (b, c, e, f). (b) S–a 1.071, a–c 1.250, a–d 1.042, d–e 1.053, d–f 1.400, S–b 1.111; mean 1.154. d–f is the most tortuous. (c) Strahler: tips c, e, f, b: order 1; d–e and d–f are both 1, so a–d has order 2; at a, a–c (1) and a–d (2) differ: S–a has order 2; S–b order 1. Centrifugal: S–a and S–b 1; a–c and a–d 2; d–e and d–f 3. (d) N(20) = 2 (S–a, S–b); N(50) = 3 (a–c, a–d, S–b); N(65) = 3 (a–c, d–e, d–f); N(80) = 1 (d–f). The profile rises from 2 to 3, stays at 3 up to about 70, then falls to 1 and to 0 after 90.
B2. (a) Mean \mathrm{DT} = 3.32; diameter 6.64 pixels. (b) s = 4.5/\sqrt2 = 3.18 pixels, close to the radius 3.32 from (a). Both measure the size of the vessel, by different routes: the scale from the filter, the radius from the mask. They agree only roughly, because the vessel’s profile is not exactly Gaussian. (c) A lower threshold makes the mask wider, so \mathrm{DT} on the skeleton grows and the radius is overestimated. The skeleton barely moves (it stays in the middle), but more noise survives, so more spurs. The radius from the mask is only as good as the threshold.
B3. (a) Closest pairs first: (95, 90)–(95, 92) 2.00; (20, 30)–(22, 31) 2.24; (80, 40)–(81, 43) 3.16; (45, 32)–(47, 36) 4.47. Missed: (60, 70). Spurious: (70, 75) and (30, 80). 4 matched, 1 missed, 2 spurious. (b) Precision 4/6 = 0.67; recall 4/5 = 0.80. (c) Probably the same junction, found 11 pixels away from its true place: in a narrow fork the skeleton’s junction moves along the trunk. With a tolerance of 12 pixels it would count as found; the tolerance decides, and must be reported.
B4. (a) A gap at the junction: the side branch is cut off; one branch point lost, two (or three) extra end points, the edges split; a little length lost. (b) The two vessels merge into one wide object: one edge instead of two, branch points lost; length roughly halved there, radius overestimated. (c) A blob on a vessel: vesselness is low on the blob itself (gap) or the mask bulges; the skeleton gets short spurs (spurious branch points and end points). (d) Many short spurs everywhere: spurious branch points and end points, the total length inflated.
B5. (a) Side 256 × 2 µm = 0.512 mm, area 0.262 mm²; length 1109 × 2 µm = 2.218 mm; length density 2.218 / 0.262 = 8.46 mm/mm²; branching density 12 / 0.262 = 45.8 per mm². (b) Counts grow with the imaged area and length in pixels with the resolution; densities in physical units (mm/mm², per mm²) do not, so they can be compared between images, microscopes and studies. Always convert with the pixel size.
Math questions
B6. (math) Murray’s law: at a bifurcation r_0^3 = r_1^3 + r_2^3. (a) For a symmetric split, express r_1 in terms of r_0. (b) A parent of radius 5 gives a child of radius 4. What radius does the other child have? (c) Laminar flow through a tube scales as Q \propto r^3 under Murray’s optimum. Show that the law means the flow is conserved at the bifurcation.
B7. (math) Show that a circular arc of opening angle \varphi has tortuosity \tau = \dfrac{\varphi/2}{\sin(\varphi/2)}. Evaluate it for \varphi = 90°, 120° and 180°. What does \tau tend to for small \varphi?
B8. (math) Prove the rule for the Strahler order of a balanced binary tree: if every branch point has two children of equal order and there are 2^k tips, the root edge has order k + 1.
B6. (a) r_0^3 = 2r_1^3, so r_1 = 2^{-1/3} r_0 = 0.794\,r_0. (b) r_2 = (125 - 64)^{1/3} = 61^{1/3} = 3.94. (c) With Q_i = k\,r_i^3: Q_1 + Q_2 = k(r_1^3 + r_2^3) = k\,r_0^3 = Q_0: what flows into the bifurcation flows out.
B7. Radius R: arc length L = R\varphi; the chord subtends the angle \varphi at the centre, so C = 2R\sin(\varphi/2); \tau = R\varphi / (2R\sin(\varphi/2)) = (\varphi/2)/\sin(\varphi/2). \varphi = 90°: (\pi/4)/\sin(\pi/4) = 1.111; 120°: (\pi/3)/\sin(\pi/3) = 1.209; 180°: \pi/2 = 1.571. For small \varphi, \sin x \approx x - x^3/6, so \tau \approx 1 + \varphi^2/24 \to 1: a gentle arc is nearly straight.
B8. By induction over k. k = 0: one tip, its edge has order 1. Step: a balanced tree with 2^{k+1} tips is a root edge whose branch point has two balanced subtrees with 2^k tips each; by induction both have order k + 1; equal orders meet, so the root edge has order k + 2.
Explore
A synthetic neuron or vessel network with its known graph. The tabs show the steps: image, vesselness (multi-scale, σ min to σ max), mask (hysteresis threshold of the vesselness; specks below 30 pixels removed, holes up to 20 pixels filled), skeleton (pink: pruned spurs), graph (blue: end points, red: junctions). Overlays: radius (skeleton coloured by \mathrm{DT}), tortuosity (edges coloured, white = straight, red = 1.33 or more), Sholl (the circle at radius r; the plot shows the whole profile, measured and true), truth (the true centreline in cyan; red circles: missed branch points, orange squares: spurious ones; matching within 8 pixels). The table compares the measurements with the truth; length picks the estimator. The generator section changes the tree and the image.
E1. Preset neuron: Sholl profile. Read the measured and true total length, end points, branch points and primary branches. Where is the maximum of the Sholl profile, and how many crossings does it have? Drag the Sholl radius to 30 and 90 and compare with the figure of the lecture.
E2. Same preset, overlay truth. The counts of branch points agree, yet 3 are “missed” and 3 “spurious”. Find them in the image. What happened?
E3. Preset noise: spurs inflate the branch count (noise 14, no pruning). Compare end points and branch points with the truth. Now raise prune k to 8. Which numbers recover? Does the total length change much? Why?
E4. Preset vessels: length and branching density. Compare the three length estimators with the true length (preset pixel counting underestimates length switches to pixel steps). Which is closest, and by how much is pixel counting off?
E5. Same preset, overlay radius. Compare the mean radius from \mathrm{DT} with the true mean radius. Raise threshold low to 0.3 and then 0.5 (and threshold high with it): what happens to the radius, and why? Compare with the mean best σ.
E6. Preset one scale misses the thick vessels (σ = 1 only). Look at the mask of the thick vessels. What happens to length, branch points and loops? Raise σ max to 5: does it recover?
E7. Preset junctions fade: branch points lost. Look at the vesselness tab at the branch points. How many branch points are found, and how many end points? Lower threshold low step by step: from which value are all branch points found?
E8. Preset tortuous vessels. Compare the measured and true mean tortuosity, and the number of loops. Why are there more loops in the measurement than in the truth?
E1. Length 1062 (corrected) against 1076; 15 end points, 10 branch points and 5 primary branches, all as in the truth. The measured profile peaks at 15 crossings at r = 100 (truth: 15 at r = 96). At r = 30 the measured profile gives 6 and the truth 7; at r = 90, 12 and 14: near some forks the measured branch point lies on the other side of the circle.
E2. In three narrow forks (two branches leaving at a small angle) the skeleton’s junction lies more than 8 pixels further along the trunk than the true branch point: each such fork counts once as missed (true point unmatched) and once as spurious (measured point unmatched). The number is right, the position is not: a matching tolerance must fit the expected displacement.
E3. Without pruning: 22 end points and 17 branch points (truth: 15 and 10); 10 spurious branch points. With k = 8: 15 and 10 again (3 missed, 3 spurious, the forks of E2). The total length barely changes (1081 → 1074): spurs are short, they distort counts much more than lengths.
E4. True length 1138. Pixel steps 989 (−13 %), 1/√2 1161 (+2 %), corrected 1109 (−2.5 %). The corrected and 1/√2 estimates are close; pixel counting is off by the most. (The remaining error also includes the skeleton ending one radius short of each tip.)
E5. Mean radius 4.27 from \mathrm{DT}, true 2.66: the mask is wider than the vessels, because the vesselness is spread out by the filter’s scale and the low hysteresis threshold (0.15) accepts its outer parts. With threshold low 0.3: 3.73; with high and low at 0.5: 3.18. The best σ (about 3.1) also grows with the vessel size, but it measures the filter’s scale, not the wall: both are proxies that must be calibrated.
E6. With σ = 1 only, the thick vessels become hollow: the filter responds to their two edges, not to the whole tube, and the mask has two parallel lines. Length 1377 against 1138 (+21 %), only 8 of 12 branch points found, the loop lost, radius 1.49. With σ max = 5 the thick vessels fill in again: length 1109, 12 branch points, 1 loop.
E7. At the junctions the vesselness is dark: there both curvatures are large and the filter takes them for blobs. With both thresholds at 0.85, only 2 of 12 branch points are found and there are 30 end points (truth 12); length 989. Lowering threshold low (high still 0.85): 0.8 gives 8 branch points and 20 end points, 0.7 gives 10 and 14, and from 0.65 down all 12 branch points and 12 end points are found (none missed): hysteresis bridges the faint junctions by keeping weak pixels that connect to strong ones.
E8. Mean tortuosity 1.299 measured, 1.341 true. 3 loops measured, 2 true: where a tortuous vessel bends back and touches itself or a neighbour, the mask merges them and creates a cycle that does not exist (failure mode “touching vessels”). Some edges are also split at the false junctions, which lowers their individual tortuosity.
Code
Write the algorithms of this unit yourself, in Rust. Setup, and how to run and check your code: coding exercises: getting started. Your code goes in skeleton/src/skel_neurovessel/exercise.rs. The code works on a tree file, as on the lecture slide “Tracing: what neuroscientists use”: a list of points, each with a position, a radius and the number of its parent point; the root (the soma) has none, and every point comes after its parent. children(tree) is given.
C1. tree_counts(tree): the total length (the sum of the distances from each point to its parent), the number of branch points (points other than the root with two or more children) and of tips (points without children). The check is B1(a).
C2. branches(tree): the branches between nodes, with path length and chord:
for every node s (the root, or a point with two or more children):
for every child c of s:
follow single children from c until a point with zero or several children: the end e
length = sum of the segment lengths on the way; chord = distance from s to e
Tortuosity is length / chord. The checks are the six edges of B1 and a half circle (B7: \pi/2).
C3. strahler(tree): the order of every point (of the segment to its parent):
for every point p, from the last to the first: # children come after their parents
if p has no children: order(p) = 1
else:
m = largest order among the children
order(p) = m + 1 if two or more children have order m, else m
The checks are B1(c) and the balanced tree of B8.
C4. sholl(tree, cx, cy, radii): for each radius r, count the segments (point to parent) with one end closer to the centre than r and the other end at r or farther. The check is B1(d).
C5. match_points(truth, measured, tolerance): all pairs within the tolerance, closest first; a pair is accepted if neither point is used yet. The rest are missed (true) and spurious (measured) points. The check is B3.
Then cargo run -p skeleton -- skel-neurovessel and open out/skel-neurovessel/neuron.png. The program grows a synthetic neuron (a soma with 5 dendrites that split up to three times, with radii following Murray’s law), prints its measurements and Sholl profile, and draws it coloured by Strahler order, with the branch points in white and the Sholl circle of the maximum in grey. Last, it “measures” the branch points: the true ones moved by about 3 pixels at random, one of them lost, two spurious ones added, and matches them at the tolerances 2, 4 and 8 pixels.
C6. Read the numbers of tips and branch points. In B8 a tree with junctions of degree 3 has two more tips than junctions. What is the relation here, and why? How many branches of each Strahler order are there?
C7. Read the Sholl profile. Why is N(r) the same for r = 10, 20 and 30? Where is the maximum?
C8. Read the matching results. Why does a tolerance of 2 pixels find almost nothing? Which tolerance would you report, and what are the missed and spurious points at that tolerance?
The model solution is skeleton/src/skel_neurovessel/solution.rs in the download.
C6. 412 points, total length 1258 pixels, 5 primary branches, 24 branch points and 29 tips: 29 = 24 + 5. Counting degrees as in B8, with the soma as one more node of degree 5: n + 3J + 5 = 2E and E = n + J (a tree with n + J + 1 nodes), so n = J + 5; in general n = J + (\text{primary branches}). Of the 53 branches, 29 have Strahler order 1 (the tips), 14 order 2, 8 order 3 and 2 order 4: the number drops by a factor of about 2 per order (2.1, 1.8, then 4 for the last, small step), the pattern of Horton’s ratios.
C7. N(r) = 5 for r = 10 to 30: close to the soma only the 5 primary dendrites cross the circles, as they have not split yet. The profile then rises (8, 10, 14, 16) to a maximum of 19 crossings at r = 80, falls to 7 at 100 and 1 at 110, and is 0 from 120 on, beyond the last tip.
C8. The measured points lie 1 to 8 pixels from the true ones, typically 3 to 4 (3 pixels at random in x and in y), so a tolerance of 2 pixels matches only 4 of 24. At 4 pixels: 15 matched, 9 missed, 10 spurious; at 8 pixels: 22 matched, precision 0.88, recall 0.92. The tolerance must fit the expected displacement, so 8 here. Then the 2 missed points are the lost one and one that moved more than 8 pixels, and the 3 spurious points are the 2 added ones and that same displaced point, which counts twice (as in E2).
Where this leads
The measurements of this day become per-object columns in the labelling day’s table, and their comparison between groups is the subject of the evaluation and statistics day. In 3D, the same pipeline works on stacks with a 3 × 3 Hessian and 3D thinning; the marching-cubes day covers volumes and voxel spacing. Thin structures are also where segmentation by energy minimisation struggles (the shrinking bias of the graph-cut day), and where learned segmentation (U-Nets) is now often used to produce the mask that is then skeletonised. Tracing a single branch between two clicked points is a minimal-path problem: live-wire and fast marching on the dynamic programming day.