Skip to content

Enclosed media

Pockets of medium that the tissue encloses: their own regions, flagged as media, instead of part of a cell.

Why this exists

The watershed places one seed per label value, at the label's largest EDT value. The medium, label 0, is one value, so before 0.7.1 it had one seed, in whichever of its pieces was deepest. An enclosed pocket of label 0 (a lumen, a cavity) had none: its tetrahedra formed one unseeded group, which the first seeded cell it reached took whole. On a 697-cell embryo with a 389 918-voxel lumen, one lining cell came out at 2.40 times its voxel volume, and no lining cell kept a membrane against the lumen. When a pocket was deeper than the exterior (a tight crop), label 0's seed fell in the pocket and the exterior was absorbed instead.

What it does

Pieces of label 0 are 6-connected (two voxels sharing a face), as foambryo's mask report counts them. A piece touching no face of the array is an enclosed pocket. A pocket becomes its own region, flagged as a medium, when its inscribed radius is at least min_distance + 1 voxels and at least two cells line it:

  • the inscribed radius is the largest Euclidean distance, in voxels, from a pocket voxel to the nearest voxel outside the pocket. Below about 3 voxels at min_distance 3 a pocket holds no tetrahedron, and a seed placed in it would take a neighbouring cell's tetrahedron instead, so it is left as before;
  • a pocket lined by one cell is a hole in that cell's segmentation, not a lumen between cells: as its own region it would be a closed surface with no triple line, whose tension no method can infer. It is left as before.

The new labels are max + 1, max + 2, ..., in the order of each pocket's lowest raster (C-order) index. Pockets left as before are reported, and EnclosedMediumWarning names the cell that took each.

Every piece of label 0 that touches the image box is exterior and gets its own label-0 seed (see dw3d.reconstruction_algorithm). A mask with no pocket at or above the bound and one exterior piece is reconstructed bitwise as before.

Herve Turlier's group, 2026.

UnresolvedCellWarning

Bases: UserWarning

Some regions of the mask are absent from the mesh.

Emitted once per reconstruction whose finished mesh lacks a label of the mask that was meshed, whatever the cause, naming each such region with its voxel count, the cause and the min_distance; the regions are the reconstruction's enclosed_medium_report.unresolved. A smaller min_distance may mesh them. The causes:

  • no tetrahedron centroid lies in the region's voxels (a cell a few voxels thick, or smaller than the point placement's min_distance). A region's watershed seed is the tetrahedron whose centroid is nearest to its deepest voxel; here that tetrahedron belongs to a neighbour, and before 0.7.1 the region grew from it inside the neighbour, as a phantom. Since 0.7.1 the seed is dropped.
  • the region was seeded, but the watershed left it few tetrahedra (often only its seed: the rest of the region, grouped without the seed, went to a neighbour) and mesh surgery relabelled those. Since 0.8.0 such a region is named too; before, only CellVolumeDisagreementWarning listed it, as a cell absent from the mesh.
  • the region had no watershed seed (label 0 when no piece of it touches the image box), or holds tetrahedra but no triangle of the finished mesh.

EnclosedMediumWarning

Bases: UserWarning

Enclosed pockets of medium were left to the cells around them.

Emitted once per reconstruction that leaves at least one pocket of label 0 to the cells (below the size bound, or lined by one cell). The pockets are the reconstruction's enclosed_medium_report.pockets_left_to_cells. A subclass of :class:UserWarning, so it can be silenced or promoted to an error on its own with :func:warnings.filterwarnings.

EnclosedMedium dataclass

EnclosedMedium(label: int, voxels: int, inscribed_radius: float, lining_cells: tuple[int, ...])

An enclosed pocket of medium that became its own region.

Attributes:

Name Type Description
label int

its label in the reconstructed mask and mesh.

voxels int

its voxel count.

inscribed_radius float

the largest distance from one of its voxels to the nearest voxel outside it, in voxels of the grid that was meshed.

lining_cells tuple[int, ...]

the labels 6-adjacent to it, ascending.

UnresolvedRegion dataclass

UnresolvedRegion(label: int, voxels: int, kind: str, cause: str = NO_TETRAHEDRON_IN_ITS_VOXELS, tetrahedra_after_the_watershed: int | None = None, tetrahedra_in_its_voxels: int | None = None)

A region of the mask that is absent from the finished mesh.

Attributes:

Name Type Description
label int

its label in the mask that was meshed.

voxels int

its voxel count.

kind str

"cell", "enclosed medium" or "exterior" (a piece of label 0 touching the image box).

cause str

"no tetrahedron in its voxels" (its seed was dropped), "removed by mesh surgery" (seeded, but surgery relabelled what the watershed left it), "no watershed seed", or "no triangle in the mesh".

tetrahedra_after_the_watershed int | None

how many tetrahedra the watershed gave it (None when its seed was dropped).

tetrahedra_in_its_voxels int | None

how many tetrahedra have their centroid in its voxels (numpy.rint), that is, what a labelling by centroids would give it (None when its seed was dropped: 0).

PocketLeftToCells dataclass

PocketLeftToCells(voxels: int, inscribed_radius: float, lining_cells: tuple[int, ...], reason: str, absorbed_by: int | None = None)

An enclosed pocket of medium left to the cells around it, as before 0.7.1.

Attributes:

Name Type Description
voxels int

its voxel count.

inscribed_radius float

as EnclosedMedium.inscribed_radius.

lining_cells tuple[int, ...]

the labels 6-adjacent to it, ascending.

reason str

"below the size bound", "lined by one cell", or "switched off" (the reconstruction's label_enclosed_media is False).

absorbed_by int | None

the region that took most of the volume of the tetrahedra whose centroid lies in the pocket; when none does, the region of the tetrahedron whose centroid is nearest to the pocket's deepest voxel. Usually a lining cell; it can be 0 (a pocket of a few voxels next to the exterior). None before the reconstruction's watershed has run.

EnclosedMediumReport dataclass

EnclosedMediumReport(media: tuple[EnclosedMedium, ...] = (), pockets_left_to_cells: tuple[PocketLeftToCells, ...] = (), exterior_pieces: int = 0, min_inscribed_radius: float = 0.0, unresolved: tuple[UnresolvedRegion, ...] = (), min_distance: int | None = None, moved_seeds: tuple[int, ...] = (), exterior_seeds_changed: bool = False, has_medium: bool = False)

The pieces of medium of one reconstruction: the enclosed media made, the pockets left, the exterior.

Attributes:

Name Type Description
media tuple[EnclosedMedium, ...]

the enclosed pockets that became their own regions, by label.

pockets_left_to_cells tuple[PocketLeftToCells, ...]

the enclosed pockets left to the cells, in the order of their lowest raster index.

exterior_pieces int

the pieces of label 0 that touch a face of the array, each of which gets a seed.

min_inscribed_radius float

the size bound used, in voxels.

unresolved tuple[UnresolvedRegion, ...]

the regions of the meshed mask absent from the finished mesh, by label, each with its cause (filled by the reconstruction; UnresolvedCellWarning).

min_distance int | None

the point placement's min_distance the reconstruction used (None when unknown).

moved_seeds tuple[int, ...]

labels whose seed's nearest tetrahedron lay outside their own voxels and was replaced by the nearest one inside (filled by the reconstruction).

exterior_seeds_changed bool

whether label 0's seeds differ from the one seed a single label gets (two or more exterior pieces, or the deepest voxel of label 0 in a pocket left to the cells; filled by the reconstruction).

dropped_seeds property

dropped_seeds: tuple[int, ...]

The labels of the unresolved regions, ascending.

unresolved_cells property

unresolved_cells: tuple[int, ...]

The labels of the unresolved regions that are cells, ascending.

changes_the_mesh property

changes_the_mesh: bool

Whether any of the three rules acted, so that the mesh may differ from 0.7.0's on the same tesselation.

False means: no enclosed medium made, label 0 seeded as before, every seed already inside its label. The reconstruction is then bitwise what it was (pockets left to the cells are left as before).

medium_labels property

medium_labels: tuple[int, ...]

The labels that are media: 0 first when the mask has it, then the enclosed media, ascending.

as_dict

as_dict() -> dict

A JSON-serialisable copy of the report.

MediumPieces dataclass

MediumPieces(exterior_count: int = 0, exterior_components: NDArray[int32] | None = None, exterior_ids: tuple[int, ...] = (), left: list[_Pocket] = list())

The pieces of label 0 of a mask, kept for the reconstruction's seeding and its report.

Attributes:

Name Type Description
exterior_count int

the pieces touching a face of the array.

exterior_components NDArray[int32] | None

the component image, kept only when there are two or more exterior pieces (to seed each), else None; exterior_ids are its exterior components, in raster order of their first voxel.

left list[_Pocket]

the enclosed pockets left to the cells.

find_enclosed_media

find_enclosed_media(mask: NDArray[integer], min_inscribed_radius: float) -> tuple[NDArray, EnclosedMediumReport]

Give each enclosed pocket of label 0 lined by two or more cells, and deep enough, its own label.

Parameters:

Name Type Description Default
mask NDArray[integer]

the 3-D integer label mask; label 0 is the medium. Never modified.

required
min_inscribed_radius float

the smallest inscribed radius, in voxels, of a pocket that becomes its own region (the reconstruction uses its placement's min_distance + 1).

required

Returns:

Name Type Description
tuple NDArray

the mask to mesh (mask itself when no pocket becomes a region, else a relabelled copy whose dtype

EnclosedMediumReport

is widened if the new labels need it) and the report (absorbed_by of each pocket left is None here).

label_enclosed_media

label_enclosed_media(mask: NDArray[integer], min_inscribed_radius: float, *, make_regions: bool = True) -> tuple[NDArray, EnclosedMediumReport, MediumPieces]

find_enclosed_media, plus the pieces the reconstruction's seeding and report need afterwards.

With make_regions=False no pocket becomes a region (every pocket is left, reason "switched off"), so the mask is returned as is; the pieces are still found, for the exterior seeding and the report.

unresolved_message

unresolved_message(report: EnclosedMediumReport) -> str

The text of UnresolvedCellWarning for one report: one sentence per cause, the regions by label.

warning_message

warning_message(report: EnclosedMediumReport) -> str

The text of EnclosedMediumWarning for one report (with absorbed_by filled).