Skip to main content
Tile specification dataclass. Defines TileSpec, a pure data structure describing tile geometry (size, stride, resolution, measurement unit). This module lives in the data layer so it can be imported by both bioptimus.extraction and bioptimus.models without creating circular dependencies. For backward compatibility, TileSpec is re-exported from types.

TileSpec

@dataclass(frozen=True)
class TileSpec()
Defines the specifications of a tile within a WSI for extraction.
size
The size of the tile as (width, height) or a single integer for both dimensions.
stride
The stride of the tile as (stride_width, stride_height) or a single integer for both dimensions.
resolution
The resolution at which the tile is defined.
unit
The unit of measurement for the tile dimensions.
Example:
>>> spec = TileSpec(
...     size=(256, 256), stride=(128, 128),
...     resolution=Resolution(level=0),
...     unit=MeasurementUnit.PIXELS,
... )
>>> print(spec.size)
(256, 256)

size

(width, height)

stride

(stride_width, stride_height)

width

@property
def width() -> int
Returns the tile width.

height

@property
def height() -> int
Returns the tile height.

stride_width

@property
def stride_width() -> int
Returns the horizontal stride.

stride_height

@property
def stride_height() -> int
Returns the vertical stride.

scale_to_reference

def scale_to_reference(downsample_ratio: float, mpp: MPP) -> TileSpec
Returns a new TileSpec scaled to reference-level pixels.
downsample_ratio
float
required
Ratio of the reference-level downsample to the target-resolution downsample.
mpp
MPP
required
Microns-per-pixel at the target resolution.
returns
TileSpec
A new TileSpec in reference-level pixels.
Raises:
  • ValueError — If unit is not PIXELS or UM.