MegaTileExtractor class, which groups individual tile positions from a Whole Slide Image into mega tiles — fixed- size grids of rows × cols tiles. It builds on the tile-level tissue filtering from TileExtractor and adds a second filtering stage: only mega tiles where the fraction of tissue-positive tiles falls within a configurable [min_valid_tiles_ratio, max_valid_tiles_ratio] band are kept.
The class follows the same scikit-learn–style lifecycle as TileExtractor:
- Configure — instantiate with a
MegaTileSpec, optional tissue mask, and threshold. - Fit — call
fitwith an openWSIReader. - Extract — call
extract(or the shortcutfit_extract). Results are stored inmegatile_regions_and also returned. - Export — call
to_csvorto_jsonto persist the results.
MegaTileExtractor
- Tile-level filtering — a binary tissue mask and
mask_thresholddetermine which individual tile positions contain sufficient tissue. - Mega-tile-level filtering — only mega tiles where the fraction of valid (tissue-positive) tiles falls within
[min_valid_tiles_ratio, max_valid_tiles_ratio]are retained.
TileExtractor:
Mega-tile grid shape, per-tile spec, layout, stride, and valid-ratio bounds.
Binary tissue mask.
Per-slide mask generator.
Per-tile tissue fraction threshold.
Whether to store per-tile masks.
Optional cap on returned mega tiles. Fitted attributes (populated by
fit / extract):Bound WSI reader.
Stem of the slide filename.
Extracted mega tiles.
fit
mask_provider is set, its generate method is called to create a per-slide tissue mask.
An open WSI reader.
self for method chaining.extract
- Reference-level setup — as in
TileExtractor. - Mask scaling — resize tissue mask to the reference level.
- Tile-spec scaling — convert tile dimensions to reference-level pixels.
- Per-tile tissue evaluation — build an integral image and compute the tissue fraction for every candidate tile position.
- Mega-tile grouping — slide a
rows × colswindow (in tile units) across the tile grid, collect per-tile validity, and filter by[min_valid_tiles_ratio, max_valid_tiles_ratio].
megatile_regions_ and returned.
An open WSI reader. When given, the extractor is fitted automatically. Otherwise
fit must have been called.Mega-tile regions that pass filtering.
RuntimeError— If no source is provided andfithas not been called.
fit_extract
fit + extract in one call.
An open WSI reader.
Extracted mega-tile regions.
to_csv
megatile_index, megatile_top, etc.) allow grouping.
Destination directory (created if needed).
Override the stored regions. Defaults to
megatile_regions_.Path of the written CSV file.
RuntimeError— If no regions are available.
to_json
tiles array with per-tile metadata.
Destination directory (created if needed).
Override the stored regions.
JSON pretty-printing indent.
Path of the written JSON file.
RuntimeError— If no regions are available.

