morphogen.analysis.stereology

Stereology: the sections of a phase by the planes of the grid, and the recovery of the size distribution of its particles from them (Wicksell 1925; Saltykov 1967), for spheres and for aligned ellipsoids of a common shape and orientation, as Degdeg & Dirrenberger for the pores of a copper foam.

A plane normal to the unit vector n at the distance d from the centre of the ellipsoid x . M x = 1, M^-1 = R diag(a^2, b^2, c^2) R^T, cuts it in an ellipse of area pi abc (s - d^2) / s^(3/2), s = n . M^-1 n. Uniformly placed particles have u = d / sqrt(s) uniform over [-1, 1]: the equivalent radius of their sections is r = r_max sqrt(1 - u^2), the law of a sphere, F(v) = 1 - sqrt(1 - v^2) for v = r / r_max, with r_max = kappa a, kappa = sqrt(l1 l2) / s_hat^(1/4) for the shape factors l1 = b/a, l2 = c/a and s_hat = n . R diag(1, l1^2, l2^2) R^T n; the planes of a family cut the particles in proportion to their height H = 2 a sqrt(s_hat). On classes of radii of width delta, a particle of the 3D class I (r_max = I delta) gives a section of the 2D class J <= I with the probability P_IJ = (sqrt(I^2 - (J - 1)^2) - sqrt(I^2 - J^2)) / I (the Scheil–Schwartz–Saltykov matrix), so that the areal densities of the sections are N_A,J = sum_I P_IJ H_I N_V,I, inverted class by class from the largest.

class morphogen.analysis.stereology.Sections(axis: int, radii: ndarray, weights: ndarray, area: float)[source]

Bases: object

The sections of a phase by the planes normal to axis: their equivalent radii sqrt(area / pi), their weights (1, or the Miles–Lantuéjoul factor of a section inside the frame of a non-periodic image) and the total area of the planes.

areal_density(edges) → ndarray[source]

Sections per unit area in the classes of radii between edges.

mean_radius() → float[source]

Number mean of the section radii.

morphogen.analysis.stereology.section_sizes(image, phase: int = 1, axis: int = 2, *, separate: bool = False, prominence: float | None = None, min_radius: float = 0.0, periodic=None) → Sections[source]

The sections of phase by the planes of voxels normal to axis (8-connected pixels). separate: touching sections are split by a watershed of their distance map from its maxima of prominence at least prominence (physical units, default half a pixel), in the manner of the binary watershed of Fiji. Sections of equivalent radius below min_radius are dropped. On periodic images each section counts once, whole across the faces; otherwise the sections cut by the frame are dropped and the others weighted by n1 n2 / ((n1 - 1 - w1)(n2 - 1 - w2)) for their extents w in pixels (Miles–Lantuéjoul).

morphogen.analysis.stereology.saltykov_matrix(n: int) → ndarray[source]

P[I - 1, J - 1]: the probability that a particle of the 3D class I (largest section radius I delta) is cut in a section of the 2D class J (radii between (J - 1) delta and J delta), classes counted upward; its rows sum to 1.

morphogen.analysis.stereology.section_scales(shape=(1.0, 1.0), rotation=None, axis: int = 2) → tuple[float, float][source]

(kappa, h): an ellipsoid of short semi-axis a, shape factors shape = (b/a, c/a) and axes rotation (columns: the directions of its axes a, b, c in the frame of the image; default x, y, z) is cut by the planes normal to axis in sections of equivalent radius at most kappa a, and spans h a across them. From a fabric tensor f: shape = (f.ratios[1], f.ratios[0]), rotation = f.axes[:, ::-1].

class morphogen.analysis.stereology.Unfolding(radii: ndarray, density: ndarray, directional: ndarray, scales: ndarray, measured: ndarray, refolded: ndarray, errors: ndarray, axes: tuple[int, ...])[source]

Bases: object

A 3D size distribution recovered from sections: the short semi-axes of its classes (radii, on the mean scale of the directions) and their numbers per unit volume (density, the mean of the directions); per direction (axes), the densities (directional), the largest short semi-axis a_max (scales), the measured and refolded areal densities of the 2D classes and the relative L1 error of the refolding.

fractions() → ndarray[source]

Number fractions of the classes.

distribution() → Discrete[source]

The number distribution of the short semi-axes (classes of negative density dropped), e.g. the seed_radius of a LevelSetFoam.

morphogen.analysis.stereology.unfold_sections(sections, *, shape=(1.0, 1.0), rotation=None, bins: int = 20, classes: int | None = None, percentile: float = 99.0) → Unfolding[source]

The size distribution of particles of a common shape (shape, rotation: see section_scales()) from their sections normal to one or several axes (a Sections or a list), as Degdeg & Dirrenberger: in each direction the sections up to the percentile of their radii, r_max, fall in bins classes of width r_max / bins, and the classes largest 3D classes (short semi-axes I / bins of a_max = r_max / kappa) come from Saltykov’s recursion; their densities are averaged over the directions class by class. classes=None: the number that minimizes the summed L1 error of refolding the mean through each direction (several directions: with one, the refolding of all the classes is exact).

morphogen.analysis.stereology.shape_consistency(sections, shape=(1.0, 1.0), rotation=None) → ndarray[source]

The mean section radius over kappa in each direction (the axes of sections, a list of Sections or a mapping axis -> mean radius): (pi / 4) m2 / m1 of the short semi-axes in every direction when the particles have the given shape.

morphogen.analysis.stereology.consistent_shape(sections, rotation=None) → tuple[float, float][source]

The shape factors (b/a, c/a) for which shape_consistency() is the same in the three directions: r_D^4 s_hat_D common to them, a linear system in the squared shape factors (b/a = (r_x / r_y)^2, c/a = (r_x / r_z)^2 for the default axes). It is ill-conditioned for axes far from the planes of the grid.