Crop faces¶
Which faces of a reconstructed mesh are crop faces, and which cells the crop cuts.
The problem¶
A segmentation mask whose cells touch a face of the image box was cropped: the tissue goes on
beyond the image, and nothing beyond it was observed. The reconstruction closes every such cell
with triangles lying on the image face, the border triangles: faces of the tesselation's hull,
labelled (0, c), with the cell c on one side and nothing on the other. They are not contact
with the medium. A tension or a contact angle read on them measures the crop, not the tissue: on
plane crops of the benchmark tissues, reading them as medium contact puts 14 % to 39 % error on
the tensions of the interfaces that touch the crop (10 % to 40 % of the tissue removed), against
9 % to 13 % when they are kept out of every equation (dw3d 0.7.1's meshes).
So the reconstruction records them. A crop face is a border triangle on an image face that is not declared physical, and that its cell reaches in the mask. A cut cell is a cell with a crop face, or with a vertex on one: its volume and some of its interfaces were not observed, and its pressure is not a measurement.
The reconstruction could also close a cell on the image box where the mask's cell stops short of
the image face: with no point on the membrane in the few voxels of medium between the cell and the
face, the tetrahedra that reach the hull there took the cell's label. Since 0.8.0 such a mask is
meshed again, padded with medium on the faces no cell reaches (dw3d.thin_medium_margins), so this
is left only on a face that a cell reaches, where ThinMediumMarginWarning names the cell. Such a
border triangle is not a crop, since the cell was observed to end inside the image, and it stays
contact with the medium, as on a mesh without crop faces. On a mask none of whose cells reaches an
image face, no triangle is a crop face and no cell is cut, whatever the reconstruction put on the
hull.
Conventions¶
- A border triangle is found from the tesselation itself, not from coordinates: its three tesselation vertices form a lone face of the tesselation (a face with one tetrahedron), which lies on the hull, and the hull is the image box (the point placements put the box's eight corners in the point set). Coordinates would miss some: junction relocation moves a few border-triangle vertices off the image face (23 of 500 on one benchmark mask cut at its mid-plane).
- The image face a border triangle lies on is read from its vertices' coordinates before
relocation, in voxel units of the mask: all three have coordinate
0("axis<k>_low") orshape[k] - 1("axis<k>_high") along the same axisk. A border triangle on no single image face (none was seen) is a crop face whatever is declared physical. - A cell reaches an image face when at least one voxel of the mask on that face (index
0orshape[k] - 1along axisk) carries its label. The test is per cell and per image face, with no tolerance: a border triangle is a crop face when its cell has any voxel on the image face the triangle lies on, wherever that voxel is on the face. A border triangle on no single image face is a crop face when its cell reaches an image face, not declared physical, on which one of its vertices lies. - An image face can be declared physical (
physical_image_faces), for example a coverslip the tissue rests on: its border triangles stay contact with the medium, as before this module existed, and are not crop faces. The default declares none, because the medium beyond the image box is never observed. - The mesh is not changed: crop faces keep their labels
(0, c)and their place in the triangle array. A crop face is a row of a boolean mask beside the labels, never a reserved label: a label for the crop puts four regions around a three-face junction edge wherever the medium reaches the image face, which no reader of three-region junctions accepts.
Limits of the test, which the report lets a caller check: a cell that reaches an image face at one
place is cut, and every border triangle it has on that face is a crop face, even one far from the
place where it reaches it; and a cell that reaches a crop image face with too few voxels to get a
border triangle is not marked cut (CropFaceReport.cells_reaching_a_crop_without_a_crop_face).
On a mask that touches no image face there are no crop faces and no cut cells, and nothing else in the reconstruction depends on this module.
CropFaceReport
dataclass
¶
CropFaceReport(crop_faces: NDArray[bool_], image_face_of_triangle: NDArray[int64], cell_reaches_image_face: NDArray[bool_], cut_cells: tuple[int, ...], physical_image_faces: tuple[str, ...], image_shape: tuple[int, ...], cells_on_image_faces: tuple[tuple[int, ...], ...])
Where a reconstructed mesh meets the image box, and what that makes of its cells.
Attributes:
| Name | Type | Description |
|---|---|---|
crop_faces |
NDArray[bool_]
|
|
image_face_of_triangle |
NDArray[int64]
|
|
cell_reaches_image_face |
NDArray[bool_]
|
|
cut_cells |
tuple[int, ...]
|
labels of the cells with a crop face or with a vertex on one, sorted. |
physical_image_faces |
tuple[str, ...]
|
the image faces declared physical, in |
image_shape |
tuple[int, ...]
|
the mask's shape, which sets where the image faces are. |
cells_on_image_faces |
tuple[tuple[int, ...], ...]
|
for each face of |
n_border_triangles
property
¶
n_border_triangles: int
Border triangles, crop faces and border triangles on physical image faces together.
n_border_triangles_the_cell_does_not_reach
property
¶
n_border_triangles_the_cell_does_not_reach: int
Border triangles on an image face their cell does not reach in the mask: medium contact.
meets_the_image_box
property
¶
meets_the_image_box: bool
Whether a border triangle lies on an image face its cell reaches, crop or physical.
This is when the crop record of a file says something: save_to_rec_mesh and
save_to_vtk_mesh write it exactly then, and otherwise write the file as before crop faces
were recorded.
cells_reaching_a_crop_without_a_crop_face
property
¶
cells_reaching_a_crop_without_a_crop_face: tuple[int, ...]
Cells that reach a crop image face in the mask but are not cut cells.
Such a cell continues beyond the image, but the reconstruction put no border triangle of it on that face (it reaches the face with too few voxels), so nothing marks it cut and its pressure is reported. Empty on every mask measured so far is not a guarantee.
as_dict ¶
as_dict() -> dict
JSON-serialisable summary: counts per image face, the crop face count and the cut cells.
normalise_physical_image_faces ¶
normalise_physical_image_faces(faces: Iterable[str] | str | None) -> tuple[str, ...]
Check a declaration of physical image faces and put it in IMAGE_FACES order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
faces
|
Iterable[str] | str | None
|
names from |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: the declared faces, each once, in |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a name is not one of |
cells_on_each_image_face ¶
cells_on_each_image_face(segmented_image: NDArray[integer]) -> tuple[tuple[int, ...], ...]
The cells with at least one voxel on each face of the image box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmented_image
|
NDArray[integer]
|
the 3-D mask; label 0 is the medium. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
tuple[tuple[int, ...], ...]: for each face of |
...
|
than 0 found on the slice at index |
tuple[tuple[int, ...], ...]
|
( |
find_border_triangles ¶
find_border_triangles(triangles: NDArray[integer], tesselation_ids: ArrayLike, lone_faces: ArrayLike) -> NDArray[np.bool_]
Which mesh triangles are faces of the tesselation's hull.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triangles
|
NDArray[integer]
|
|
required |
tesselation_ids
|
ArrayLike
|
|
required |
lone_faces
|
ArrayLike
|
|
required |
Returns:
| Type | Description |
|---|---|
NDArray[bool_]
|
NDArray[np.bool_]: |
NDArray[bool_]
|
lone face, in any order. |
image_face_of_border_triangles ¶
image_face_of_border_triangles(points: NDArray[floating], triangles: NDArray[integer], is_border: NDArray[bool_], image_shape: tuple[int, ...]) -> NDArray[np.int64]
The image face each border triangle lies on, from its vertices' voxel coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[floating]
|
mesh points in voxel units of the mask, before junction relocation. |
required |
triangles
|
NDArray[integer]
|
|
required |
is_border
|
NDArray[bool_]
|
|
required |
image_shape
|
tuple[int, ...]
|
the mask's shape. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
NDArray[np.int64]: |
NDArray[int64]
|
triangle whose three vertices share no image face, |
border_triangles_the_cell_reaches ¶
border_triangles_the_cell_reaches(points: NDArray[floating], triangles: NDArray[integer], labels: NDArray[integer], image_face_of_triangle: NDArray[integer], cells_on_image_faces: tuple[tuple[int, ...], ...], image_shape: tuple[int, ...], faces: tuple[int, ...] = tuple(range(len(IMAGE_FACES)))) -> NDArray[np.bool_]
Border triangles whose cell has a voxel of the mask on the image face the triangle lies on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[floating]
|
mesh points in voxel units of the mask, before junction relocation. |
required |
triangles
|
NDArray[integer]
|
|
required |
labels
|
NDArray[integer]
|
|
required |
image_face_of_triangle
|
NDArray[integer]
|
|
required |
cells_on_image_faces
|
tuple[tuple[int, ...], ...]
|
from |
required |
image_shape
|
tuple[int, ...]
|
the mask's shape. |
required |
faces
|
tuple[int, ...]
|
the indices in |
tuple(range(len(IMAGE_FACES)))
|
Returns:
| Type | Description |
|---|---|
NDArray[bool_]
|
NDArray[np.bool_]: |
cells_touching_faces ¶
cells_touching_faces(triangles: NDArray[integer], labels: NDArray[integer], faces: NDArray[bool_]) -> tuple[int, ...]
The cells (labels other than 0) carried by a triangle that has a vertex on one of faces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triangles
|
NDArray[integer]
|
|
required |
labels
|
NDArray[integer]
|
|
required |
faces
|
NDArray[bool_]
|
|
required |
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
tuple[int, ...]: sorted labels. |
classify_crop_faces ¶
classify_crop_faces(points: NDArray[floating], triangles: NDArray[integer], labels: NDArray[integer], tesselation_ids: ArrayLike, lone_faces: ArrayLike, segmented_image: NDArray[integer], physical_image_faces: Iterable[str] | str | None = ()) -> CropFaceReport
Mark the crop faces and the cut cells of a freshly reconstructed mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
NDArray[floating]
|
mesh points in voxel units of the mask, before junction relocation. |
required |
triangles
|
NDArray[integer]
|
|
required |
labels
|
NDArray[integer]
|
|
required |
tesselation_ids
|
ArrayLike
|
tesselation index of each mesh point. |
required |
lone_faces
|
ArrayLike
|
the tesselation's faces with one tetrahedron. |
required |
segmented_image
|
NDArray[integer]
|
the mask the mesh was reconstructed from: its shape sets where the image faces are, and its voxels on them which cells reach each one. |
required |
physical_image_faces
|
Iterable[str] | str | None
|
image faces whose border triangles are contact with the medium, not crop faces. Defaults to none. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
CropFaceReport |
CropFaceReport
|
the crop-face mask, the image face of each border triangle, the cut cells. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |