Junction curves¶
Trijunction curves read from the label mask and keyed to a reconstructed mesh's own junctions.
What this is¶
extract_junction_curves returns one polyline per material triple (a, b, c), computed from
the segmentation mask, and says for each whether the reconstructed mesh has exactly one
trijunction of that same triple. The curves are more accurate than the mesh's own junction
lines and less complete than them; both halves are measured, and the API keeps them apart so a
caller cannot get one while thinking it got the other.
Nothing in the reconstruction pipeline calls this and no default changes. It is an additional read of the same mask the mesh was built from.
Where the criterion comes from¶
A dual-lattice point -- the corner shared by eight voxels -- lies on the junction line of
(a, b, c) iff those eight voxels contain all three labels. junctions.junction_strata
already computes exactly this predicate (|L| == 3) for point placement; what this module adds
is the split by material triple, the attribution of points carrying four or more labels to
every triple they contain (which carries a line into its quadruple point rather than stopping
a lattice step short), and the reduction of each 26-connected component to one ordered polyline
by the minimum spanning tree's diameter path. Label 0 is an ordinary material: the outer
medium's contact lines with the cells are genuine trijunctions.
The measured advantage, and the measured limitation¶
These curves were measured against a registered reference mesh on the 47-case synthetic benchmark, reading each variant at its own median junction-edge spacing so that the comparison is not a comparison of reading resolutions. The position error below is the median distance in voxels from a curve's vertices to the reference polyline; lower is better.
dw3d min_distance |
these curves | the mesh's own lines | advantage |
|---|---|---|---|
| 3 | 0.5796 | 0.6735 | 1.16x |
| 4 | 0.6146 | 0.7449 | 1.21x |
(42 equilibrium cases, the default reconstruction with junction relocation, dw3d 0.7.1; on 0.7.0 without
relocation the mesh's own lines sit at 0.8642 and 0.9277, and the advantage is 1.48x and 1.52x.)
Of the 24 paired comparisons of BENCHMARKS.md -- two spacings, two estimators, six geometric
metrics -- the 16 on tangent and position error favour the curves on at least 9,999 of 10,000
case-level bootstrap draws. At min_distance = 3, relative to the value the reference line itself
scores when subsampled at the same spacing, the curves read tortuosity at 1.001 (the mesh's own
lines: 1.002), curvature at 1.018 (1.024) and tangent error at 1.99x (3.35x).
They are better geometry, not correct geometry. The mask's own identifiability floor -- the best any
mask-based method can do -- is 0.107 voxels (BENCHMARKS.md, "Junction curves"). These curves sit at 0.5796,
a factor of 5.4 above it, and that gap is open.
Coordinates¶
Everything is in mask voxel units. A dual-lattice point (i, j, k) is emitted at
(i + 0.5, j + 0.5, k + 0.5), in the frame a reconstructed dw3d mesh's points live in
(construct_mesh_from_segmentation_mask; not a mesh scaled by set_pixel_size or built by
construct_mesh_in_physical_units). extract_junction_curves checks that the mesh it is given
lies inside the mask's extent (no coordinate below -1 or above the mask's size along its axis)
and refuses otherwise, because a permuted axis order would put every curve tens of voxels away
and the result would silently measure the permutation. The check sees only the extent: a mesh
scaled down into it, or permuted on a mask whose sides are nearly equal, passes it.
Provenance¶
The detection, the MST-diameter spine and the endpoint-preserving three-point filter, the per-case
reading spacing, the identity rule against the mesh's own trijunctions and the consistency test
were developed and validated on the benchmark (BENCHMARKS.md, "Junction curves"). The sub-voxel
estimator lives in junction_curve_estimator.
JunctionCurve
dataclass
¶
JunctionCurve(triple: tuple[int, int, int], points: NDArray[float64], arclength: float, matched: bool, identity: str, component: int, n_estimated: int, n_estimator_refusals: int)
One trijunction polyline read from the mask.
Attributes:
| Name | Type | Description |
|---|---|---|
triple |
tuple[int, int, int]
|
the sorted material triple |
points |
NDArray[float64]
|
the ordered polyline, shape |
arclength |
float
|
the polyline's total discrete arc length, in voxels. |
matched |
bool
|
whether the mesh has exactly one trijunction component of this same triple and this is the only component the mask gives for it. |
identity |
str
|
|
component |
int
|
index of this component within its triple, ordered by decreasing arclength. |
n_estimated |
int
|
how many of |
n_estimator_refusals |
int
|
how many it refused, leaving the detected position in place. |
JunctionCurves
dataclass
¶
JunctionCurves(matched: tuple[JunctionCurve, ...], invented: tuple[JunctionCurve, ...], fragmented: tuple[JunctionCurve, ...], match_rate: float | None, counts: dict[str, int], spacing_voxels: float | None, estimator: str, diagnostics: dict = dict())
Every trijunction curve of one case, split by whether the mesh agrees it exists.
matched is the set a caller wanting usable geometry wants: on the benchmark at
min_distance = 3 its 621 curves were measured a median 0.523 voxels from all three of their
own interfaces at once, with a p99 of 4.43. The 27 invented curves are structurally
different -- median 29.7 voxels and none within one voxel -- so they are never merged into
the same list. fragmented holds the rest: real
trijunctions the mask resolves as several pieces, or the reverse.
Attributes:
| Name | Type | Description |
|---|---|---|
matched |
tuple[JunctionCurve, ...]
|
curves one-to-one with a mesh trijunction. |
invented |
tuple[JunctionCurve, ...]
|
curves whose material triple is not a trijunction of the mesh at all. |
fragmented |
tuple[JunctionCurve, ...]
|
curves that are |
match_rate |
float | None
|
matched mesh trijunctions over all mesh trijunctions. Measured 0.900 at
|
counts |
dict[str, int]
|
|
spacing_voxels |
float | None
|
the reading spacing the polylines were resampled at -- the mesh's own median junction-edge length, so the curves are read at the resolution the mesh is. |
estimator |
str
|
which sub-voxel estimator ran -- |
diagnostics |
dict
|
dropped components, estimator statuses, timings and the frame check. |
all_curves ¶
all_curves() -> tuple[JunctionCurve, ...]
Every curve, matched first. Use matched unless completeness is what you need.
Returns:
| Type | Description |
|---|---|
tuple[JunctionCurve, ...]
|
tuple[JunctionCurve, ...]: the matched, then fragmented, then invented curves. |
mesh_trijunction_components ¶
mesh_trijunction_components(points: NDArray[float64], triangles: NDArray[int64], labels: NDArray[int64]) -> dict[tuple[int, int, int], list[dict]]
The mesh's own trijunctions, grouped by material triple and split into components.
A trijunction edge is one shared by exactly three triangles spanning exactly three
distinct materials -- Plateau's rule for a dry foam, and the same predicate
dw3d_benchmarks.metrics.edge_topology_stats and attributed_triple_line_angles apply, so
a valence->=4 defect contributes nothing here rather than contributing nonsense. This is the
line identity the reconstruction's own angle metrics are keyed to, which is why the
extracted curves are keyed to it too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[float64]
|
mesh vertex coordinates, |
required |
triangles
|
NDArray[int64]
|
triangle vertex indices, |
required |
labels
|
NDArray[int64]
|
the two materials each triangle separates, |
required |
Returns:
| Type | Description |
|---|---|
dict[tuple[int, int, int], list[dict]]
|
dict[tuple[int, int, int], list[dict]]: per sorted triple, its connected components, |
dict[tuple[int, int, int], list[dict]]
|
each |
dict[tuple[int, int, int], list[dict]]
|
smallest vertex index so the ordering does not depend on dictionary iteration order. |
mesh_junction_spacing ¶
mesh_junction_spacing(components: dict[tuple[int, int, int], list[dict]]) -> float | None
The mesh's own median trijunction-edge length, in voxels.
This is the resolution at which the mesh states its junction lines, and therefore the resolution at which a competing curve must be read for the comparison to be about accuracy rather than about how finely each side was sampled. It is derived from the mesh alone: no reference, no mask, no parameter.
The statistic is the median over components of each component's own median edge length, which is the statistic the junction-curve validation computed from its per-line rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
dict
|
|
required |
Returns:
| Type | Description |
|---|---|
float | None
|
float | None: the spacing in voxels, or |
dual_label_sets ¶
dual_label_sets(segmented_mask: NDArray[uint]) -> tuple[NDArray[np.int64], list[frozenset[int]]]
Per dual-lattice point, an index into a table of the distinct labels around it.
A dual point (i, j, k) is the corner shared by the eight voxels
segmented_mask[i:i+2, j:j+2, k:k+2]. Points with fewer than three distinct labels are not
junctions and carry -1.
The detection itself runs slab by slab (_dual_junction_points); only the returned codes
array spans the whole volume, at 8 bytes per dual point. Code c is assigned in the order in
which its label set is first met in C order of the dual lattice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmented_mask
|
NDArray[uint]
|
the label image. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
tuple[NDArray[np.int64], list[frozenset[int]]]: |
list[frozenset[int]]
|
table where |
subsample_indices ¶
subsample_indices(path: NDArray[float64], spacing: float) -> NDArray[np.int64]
Indices of a subset of a polyline's own vertices, spaced by about spacing in arclength.
Every retained point lies exactly on the original polyline, so this coarsens the reading
without adding positional error. Targets are laid out at exact multiples of spacing and
the nearest own-vertex is taken for each; taking the first vertex past each threshold
systematically overshoots the requested spacing.
Indices rather than points, because the sub-voxel estimator has to read its line direction from the un-coarsened polyline -- at an 8-voxel spacing a three-voxel chord between retained vertices does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
NDArray[float64]
|
the polyline, shape |
required |
spacing
|
float
|
the target spacing in voxels; |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
NDArray[np.int64]: ascending indices into |
detect_junction_spines ¶
detect_junction_spines(segmented_mask: NDArray[uint], *, min_points: int = MIN_POINTS, smooth_passes: int = SMOOTH_PASSES) -> dict
Every material triple's smoothed lattice spine, before any reading spacing is chosen.
This is the detection half of extract_junction_curves, exposed on its own because it is
the part that reads the mask and nothing else.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmented_mask
|
NDArray[uint]
|
the label image. |
required |
min_points
|
int
|
components with fewer dual points than this are dropped and counted. |
MIN_POINTS
|
smooth_passes
|
int
|
passes of the three-point filter. Defaults to |
SMOOTH_PASSES
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
dict
|
per component) and |
extract_junction_curves ¶
extract_junction_curves(segmented_mask: NDArray[uint], points: NDArray[float64], triangles: NDArray[int64], labels: NDArray[int64], *, estimator: Estimator = 'plain') -> JunctionCurves
Trijunction curves from the mask, keyed to the mesh's own trijunctions.
The one line a user writes::
curves = extract_junction_curves(mask, *load_rec("000_mesh.rec"))
curves.matched is the usable set. Every one of its members has exactly one counterpart
among the mesh's own trijunctions of the same material triple, so it can be joined to the
interfaces and the dihedral angles the reconstruction already reports.
curves.invented is everything the mask says is a junction and the mesh does not have;
none of 27 of those were measured within one voxel of all three of their interfaces, against
a median of 0.524 voxels for the matched ones, so they are kept apart rather than merged.
curves.fragmented holds real trijunctions the mask resolves as several pieces.
Reading spacing is not a parameter: the polylines are resampled at the mesh's own median trijunction-edge length, so accuracy is compared at the resolution the mesh states its lines at rather than at whatever resolution the lattice happens to give.
Cost, and why "plain" is the default. "plain" is detection only -- no linear
program -- and costs about 0.8 s per benchmark case against the 1.49 s dw3d spends
reconstructing that case. "anchor" solves one small linear program per returned vertex and
costs roughly fifteen times as much, about eight times the whole reconstruction it
annotates, and buys 9-11 % of the position error. Nobody meshing a large tissue should pay that by default,
so they do not.
"anchor"'s real argument is not that 9 %: it is that the polytope's deepest interior point
carries only the irreducible narrow-wedge term (a) of the mask's identifiability floor,
where the detected position and the centroid both carry more. Reach for it when a
systematic bias against narrow wedges would corrupt what you are inferring, not to shave
a tenth of a voxel.
"centroid" is kept for comparison only: it was
measured carrying (a) + (b), so it is the larger systematic, not the smaller one, and it costs about
thirty times the anchor's linear programs on top.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmented_mask
|
NDArray[uint]
|
the label image the mesh was reconstructed from. |
required |
points
|
NDArray[float64]
|
mesh vertex coordinates in mask voxel units, |
required |
triangles
|
NDArray[int64]
|
triangle vertex indices, |
required |
labels
|
NDArray[int64]
|
the two materials each triangle separates, |
required |
estimator
|
Estimator
|
|
'plain'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Returns:
| Name | Type | Description |
|---|---|---|
JunctionCurves |
JunctionCurves
|
the curves, the match rate, the identity counts and the diagnostics. |