en_face_region
Placing an en-face measurement region on a scan's grid.
The region is a rectangle in millimetre space, centred on the fovea (or the scan centre), and a step crops its en-face masks to it before measuring. Every step builds the region here so no two steps can disagree on which cells it covers.
Unlike fovea_geometry, a missing fovea falls back to the scan centre: the
region is a standardisation frame rather than a fovea-relative criterion, and
the fallback is reported in the region's centre column.
Module
Functions
build_en_face_region
def build_en_face_region( spec: EnFaceRegionSpec, shape: tuple[int, int], scale: VoxelScale, fovea: tuple[float, float] | None,) ‑> EnFaceRegion | None:Place the configured region on one scan's en-face grid.
Arguments
spec: The configured region.shape:(num_bscans, num_cols)of the en-face grid, in TRUE B-scan index space.scale: The cube's voxel dimensions.fovea:(bscan, column)fovea landmark in index space, orNone.
Returns
The placed region, or None when the scan has no usable en-face scale.
Cropping with an unplaceable region would turn an unknown area into a
measured zero, so the caller leaves such a scan uncropped.
reaches_scan_edge
def reaches_scan_edge( mask: NDArray[np.bool_], region_mask: NDArray[np.bool_] | None,) ‑> bool | None:Whether a mask touches the scan's own border inside the region.
A mask clipped by the scan is truncated, so its area is a lower bound. A mask clipped only by the region's own edge is a deliberate standardisation and does not count.
Arguments
mask:(num_bscans, num_cols)mask on the grid being measured. Non-bool values are treated asTruewhen non-zero.region_mask: Region on the same grid, orNonefor no region.
Returns
True if a True cell of mask lies in the first or last row or
column and inside region_mask (any border cell when region_mask is
None); False otherwise; None for a non-2-D or empty mask.
Raises
ValueError: Ifregion_maskis given with a different shape frommask.
region_box_mask
def region_box_mask( shape: tuple[int, int], centre: tuple[float, float], width_mm: float, height_mm: float, scale: VoxelScale,) ‑> NDArray[numpy.bool]:Cells whose centres lie inside a mm rectangle about centre.
Arguments
shape:(num_bscans, num_cols)of the en-face grid.centre:(bscan, column)centre, in index space.width_mm: Extent along the column axis.height_mm: Extent along the B-scan axis.scale: The cube's voxel dimensions.
Returns
A (num_bscans, num_cols) boolean mask.
region_coverage
def region_coverage( shape: tuple[int, int], centre: tuple[float, float], width_mm: float, height_mm: float, scale: VoxelScale,) ‑> float:Fraction of the nominal region that lies on the imaged extent.
Geometric rather than a cell count, so it is exactly 1.0 for a region
inside the scan regardless of how the cell-centre rule quantises the edge.
Arguments
shape:(num_bscans, num_cols)of the en-face grid.centre:(bscan, column)centre, in index space.width_mm: Extent along the column axis.height_mm: Extent along the B-scan axis.scale: The cube's voxel dimensions.
Returns
The covered fraction, in [0, 1].
resolve_region_centre
def resolve_region_centre( spec: EnFaceRegionSpec, fovea: tuple[float, float] | None, shape: tuple[int, int],) ‑> tuple[tuple[float, float], str]:Choose the region's centre and say where it came from.
Arguments
spec: The configured region.fovea:(bscan, column)fovea landmark in index space, orNonewhen no fovea was located.shape:(num_bscans, num_cols)of the en-face grid.
Returns
The (bscan, column) centre and its REGION_CENTRE_* type.
Classes
EnFaceRegion
class EnFaceRegion( mask: NDArray[np.bool_], centre: tuple[float, float], centre_type: str, coverage: float,):A region placed on one scan's en-face grid.
Attributes
mask:(num_bscans, num_cols)boolean mask over the TRUE B-scan index space,Trueinside the region.centre:(bscan, column)centre, in index space.centre_type: One of theREGION_CENTRE_*values.coverage: Fraction of the nominal region the scan imaged, in[0, 1].
Variables
-
centre : tuple[float, float]
-
centre_type : str
-
coverage : float
-
mask : NDArray[numpy.bool]