Patch Extraction

Cutting a whole-slide image into the tiles a model actually sees — the decisions that determine what a model can learn, and which are almost never recorded.

Cutting a whole-slide image into the tiles a model actually sees — the decisions that determine what a model can learn, and which are almost never recorded.

What it is

A whole-slide image is far too large to feed to a network, so every deep-learning pipeline in pathology begins by cutting it into small tiles. This step looks like plumbing and is treated as plumbing, but it fixes the ceiling on everything downstream: a model can only learn from what a tile physically contains.

Five decisions define a tiling strategy, and all five belong in the methods section of any paper that reports a model.

Magnification, not level. The single most consequential choice, and the one most often recorded wrongly. What matters biologically is microns per pixel — whether a tile shows nuclear detail or tissue architecture. What most code exposes is a pyramid level index, which means different things on different scanners depending on how the pyramid was built. A tile extracted at “level 1” is not comparable across a mixed cohort; a tile extracted at “10x” or “0.5 µm/px” is. Any tool that cannot target magnification directly is asking you to record a number that will not reproduce — see Scanner and Stain Variability.

A fixed downsample divisor is the same mistake wearing different clothes, and PinkKidney is the group’s own worked example of it. That project exported tiles with a hardcoded downsample = 4, which is correct only if every slide was scanned at the same magnification. Its cohort is mixed — 20×, 38× and 40× — so the same divisor produced 5× tiles from the 20× slides and 10× tiles from the 40× slides, and the tiles clustered by scanner rather than by morphology. The fix is the general rule stated as code: compute the divisor per slide from the slide’s own native magnification, downsample = nativeMagnification / 10.0, so that the output magnification is the fixed quantity and the divisor varies. Worth noting how long this survived — it was caught only when a batch-effect screen showed tiles grouping by acquisition, not when the export was written.

The same institution has a worked counterexample, and it goes one step further than “compute the scale per slide”. hepatocyte-app reads openslide.mpp-x from each slide, compares it against the model’s target of 0.25 µm/px, and skips slides already at that scale. For slides that are not, it does not silently rescale and move on — it generates a second inference pass into a parallel output directory, and the viewer offers every such directory as a toggle, so a pathologist flips between native-resolution and target-equivalent inference on the same slide and sees the difference.

That is the honest handling of a resolution mismatch: when a preprocessing choice could change the answer and you cannot prove which is right, produce both and make the comparison visible rather than picking one and documenting it. The alignment detail matters too, and the project records getting it wrong first — the rerun reads the full 512 px level-0 region, downscales to match field of view, then upscales back to model input size, so the returned mask still maps 1:1 onto level-0 coordinates. An earlier version read a smaller level-0 region and produced overlays that were misaligned rather than merely rescaled.

Tile size, in pixels at that magnification. Together with magnification this sets the field of view in microns, which is the number that actually has meaning.

Stride or overlap. Non-overlapping tiles are the default. Overlap multiplies tile count and gives a smoother heatmap, but it also puts near-duplicate tiles into the dataset. Worth treating as a caution rather than a measured effect: near-duplicates spanning a train/test boundary are the same class of problem as splitting by slide when one patient contributed several blocks, and the fix is the same — split at patient level, before tiling. Whether it materially inflates results in any specific pipeline here is untested. [unverified]

The tissue filter, which decides what counts as tissue and how much of a tile must be tissue to keep it — usually a fraction of pixel area, occasionally a percentage, and the difference is a silent factor-of-100 bug. This is where WSI Quality Control connects: a tissue mask answers “where is the tissue”, QC answers “is the tissue usable”, and a tiling pipeline needs both.

Coordinate bookkeeping. Whether each tile records its level-0 x,y position. If it does not, tiles cannot be mapped back onto the slide, and no attention heatmap can ever be drawn. The convention of encoding coordinates in the filename is crude but survives everything.

Why it matters for my work

Liver Tru-Cut — Tumour Origin AI lists tile strategy definition as a current, unfinished task, and Weakly Supervised Learning records the corresponding open question — what tile size and magnification the project will settle on, and whether the choice is written down anywhere reproducible. That is the decision this page exists to support. In a MIL pipeline the tile is the instance, so tile geometry is not preprocessing, it is model design.

The tooling question was examined in July 2026 by evaluating WSITools, and the conclusion generalises past that one tool. Use tiatoolbox or pathml. Both had shipped a release within the month at the time of that review, both are PyTorch-native, and both provide tiling with tissue detection as a first-class, maintained feature — the version and activity figures behind that statement are recorded on WSITools. WSITools is dormant, TensorFlow-era, and — decisively for this page — cannot target magnification at all: it takes an OpenSlide level index and never reads the slide’s microns-per-pixel, so the very parameter that most needs recording is the one it cannot express.

Two general lessons from that evaluation are worth keeping even though they were found in one tool. A with_anno-style flag that is silently ignored because the real switch is whether an annotations object was passed is the kind of defect that produces a complete, plausible, unlabelled dataset. And a patch-label lookup that samples the wrong pixel — an off-by-a-whole- tile error — yields labels that are correct in the middle of large regions and wrong near every boundary, which is precisely where the informative tiles are. Whatever tool is chosen, the check that catches both is the same: extract a small batch, render the tiles back onto the slide at their recorded coordinates, and look at them.

How it connects

Weakly Supervised Learning — the tile is the MIL instance, so tile geometry is model design; this page holds the decision that page records as open.

Whole Slide Imaging — pyramid levels, downsamples and microns-per-pixel are the substrate every choice here is expressed in.

WSI Quality Control — runs alongside: masking finds tissue, QC decides whether it is usable, and tiles should be drawn only from regions that pass both.

Scanner and Stain Variability — a level index is scanner-dependent and a magnification is not, which is why pooling cohorts makes the magnification-versus-level distinction load-bearing.

Foundation Models in Pathology — pretrained encoders expect a specific input magnification and tile size, so the choice is partly dictated by the encoder rather than free.

QuPath Annotation Workflow — supplies the region annotations that turn unlabelled tiles into labelled ones, via GeoJSON.

Multimodal Fusion — the clearest published demonstration of what under-sampling costs: MultiSurv drew 5 patches per slide, centre-cropped to 299 px at level 0, and its image submodel scored barely above chance while adding it to the fused model made predictions worse. Two details from that code are worth carrying as cautions. The crop is a centre crop, not a resize, so the field of view is smaller than the extracted patch size suggests — a resize and a crop are not interchangeable, and only one of them preserves field of view. And the patches enter an ImageNet-pretrained network with no channel normalisation at all, which quietly wastes much of what the pretrained weights offer; if a pipeline uses pretrained features, the preprocessing has to match what those weights were trained under.

TCGA — the public cohort where the magnification-not-level problem is unavoidable, since its diagnostic slides are a mix of 40× and 20× with some magnification fields unreadable.

Agentic Slide Navigation — what replaces fixed-grid tiling when the model picks its own fields, and where this page’s µm-per-pixel argument reappears applied to actions instead of tiles.

Open questions

  • What magnification and tile size will Liver Tru-Cut — Tumour Origin AI use, and will the choice be recorded as µm/px rather than as a level index? Still unanswered.
  • Is the train/test split done at patient level? Answered for PinkKidney, and it holds up under checking. That project uses patient-level StratifiedGroupKFold, and the claim was verified against the split file rather than taken from the documentation: across 392,428 tile rows, no patient appears in more than one fold. That is the check worth copying — a grouped splitter is only as good as the group key, and confirming it costs one pass over the split table. It remains unanswered for Liver Tru-Cut — Tumour Origin AI, Paige Prostate and Aiforia Breast.
  • No tile-strategy parameters are recorded for any AI project in this wiki. Now recorded for one. PinkKidney documents 256×256 tiles at 10× effective magnification, zero overlap, PNG, with per-slide downsample computed from native magnification — and a per-slide cohort_metadata.csv carrying vendor, estimated magnification and µm/px for all 356 slides. That file is the template for closing the same gap on the other projects; the question is whether the extraction script gets pointed at their cohorts.
  • A tiling decision this page does not yet cover: what happens to tile count when patients contribute wildly different amounts of tissue. In PinkKidney the patient-level folds range from 50,332 to 100,337 tiles because grouping is by patient, so a tile-weighted metric would be dominated by a few large cases. Aggregating to patient level before scoring is the fix, and that project does it — but nothing on this page previously said to.