Skip to main content
Before any embedding or gene-expression model runs, two preprocessing steps prepare the slide:
  1. Tissue masking — a whole-slide image is mostly background. Tissue segmentation produces a binary mask so background is discarded before the expensive feature step.
  2. Tiling — the slide is too large to process at once, so it is split into small, model-sized tiles. Only tiles that overlap tissue are kept.
Resolutions differ by stage: tissue segmentation runs at 8 µm/px (coarse, 512×512 tiles), while embeddings and gene predictions run at 0.5 µm/px (224×224 tiles). The mask is generated once and reused to filter the fine-resolution grid.
The Inference pipeline does both steps for you. Reach for the manual API below only when you need masks or tiles as standalone artifacts — for QC, custom filtering, or your own pipeline.

The quick path: the Inference pipeline

Inference masks tissue, caches the result, and reuses it automatically for later embed/predict calls.
The mask is cached to <workspace>/tissue/<slide>.png and reused on the next tissue(), embed(), or predict() call. Visualize it against the slide thumbnail with the built-in helper:
Slide thumbnail alongside its binary tissue mask

Tissue mask (right) beside the slide thumbnail (left), TCGA-LUAD TCGA-75-7027. Background is discarded before feature extraction. Representative example.

The manual path: masks and tiles as artifacts

1. Generate a tissue mask

Build a mask provider from the tissue-seg endpoint. It is reusable across slides — it generates a fresh mask per slide.
Already have masks on disk? Use them directly instead of the endpoint. Non-zero pixels mean tissue, and files are matched to slides by filename stem (PNG, JPEG, TIFF, BMP, or .npy):

2. Tile the slide

A TileSpec defines the tile geometry; TileExtractor builds the grid, filters it against the mask, and exports the tiles. Passing mask_provider lets the extractor generate the per-slide mask during fit.
to_csv writes one row per retained tile: save writes each tile image as {slide}_x{left}_y{top}_w{width}_h{height}_{res}_mask_r{ratio}.png.

Tuning knobs

For end-to-end inference you rarely call these directly — the Inference pipeline handles masking and tiling and streams results to disk. Use the manual API for QC, custom region extraction, or building your own pipeline. To read regions, thumbnails, and slide metadata, see WSI processing.