Skip to main content
Tiled tissue mask generation using a batched segmentation model. Implements TiledTissueMask, which walks a WSI in fixed-size patches, processes them through a TissueMaskModel, and stitches the per-tile predictions into a full-slide binary mask.

TiledTissueMask

class TiledTissueMask(TissueMaskProvider)
Tile-based, batch-aware tissue mask generation. Combines a TissueMaskModel with a tiling strategy to produce a full-slide binary mask. The workflow is:
  1. Compute the tissue bounding box at resolution.
  2. Walk the bounding box in non-overlapping tile_size patches.
  3. Collect patches into batches of batch_size.
  4. Pass each batch to model.process() — this is where GPU parallelism happens for DL models.
  5. Stitch the per-tile masks back into the output array.
Boundary tiles that are smaller than tile_size are zero-padded before model processing and the padding is stripped from the output.
model
TissueMaskModel
The processing model.
tile_size
tuple[int, int] | None
(width, height) of each patch. When None, derived from model.tile_spec.
resolution
Resolution | None
Resolution at which to read tiles. When None, derived from model.tile_spec.
batch_size
int
Number of tiles per model call. Set higher for GPU models (e.g. 32–64). Defaults to 1.
Example:
provider = TiledTissueMask(
    model=MyGPUModel(net),
    tile_size=(512, 512),
    resolution=Level(0),
    batch_size=32,
)
mask = provider.generate(reader)

# Or let the model's tile_spec drive the defaults:
provider = TiledTissueMaskProvider(model=my_model)

generate

def generate(reader: WSIReader,
             *,
             show_progress: bool = True,
             max_concurrency: int = _DEFAULT_MAX_CONCURRENCY) -> np.ndarray
Generates a tissue mask by tiling over the WSI. Tile images are read sequentially from the WSI (readers are not thread-safe), then dispatched concurrently to the remote model endpoint for GPU-efficient batched inference. Results are stitched back into a single binary mask.
reader
WSIReader
required
An open WSI reader.
show_progress
bool
Whether to display a per-tile progress bar. Defaults to True.
max_concurrency
int
Maximum concurrent HTTP requests. Defaults to 64.
returns
np.ndarray
A uint8 mask of shape (H, W) covering the tissue bounding box at resolution, with values in {0, 1} where 1 = tissue.