Scanner and Stain Variability

The same tissue looks different depending on the scanner, the stain batch, and the laboratory — and models happily learn that difference instead of the biology.

The same tissue looks different depending on the scanner, the stain batch, and the laboratory — and models happily learn that difference instead of the biology.

What it is

Two sources of variation stack. Staining varies with H&E batch, fixation time, section thickness, and laboratory protocol, producing genuinely different colour distributions. Scanning adds its own layer: different optics, illumination, and colour processing mean two scanners produce visibly different images of the same physical slide.

For human reading this is a minor nuisance. For machine learning it is a primary confounder, because the variation is systematic and correlates with site. If your positive cases were scanned at one institution and negatives at another, a model can reach excellent internal performance by learning colour statistics and nothing else — and this failure is invisible in cross-validation, which is exactly why External Validation matters.

Standard mitigations, roughly in order of strength:

  • Stain normalisation — map images to a reference stain profile. Classical methods split into purely statistical ones (histogram matching, Reinhard) and stain-vector ones (Macenko, Vahadane); GAN-based methods learn the mapping. Cheap and helps, but can distort genuinely unusual staining — and the distortion is not evenly distributed across methods. In the strongest benchmark available, plain histogram matching beat all seven alternatives including four GAN variants, while Vahadane was the worst, overriding the hematoxylin component entirely. See Stain Normalisation for the evidence and the large caveat attached to it.
  • Colour augmentation during training — randomly perturb colour so the model cannot rely on it. Often works better than normalisation, and composes with it.
  • Multi-site training data — the strongest fix; variation the model has seen becomes variation it can ignore.
  • Grayscale or stain-invariant features — blunt, discards real information, occasionally the right call.

Related but distinct: quality control removes artefacts (blur, folds, pen marks, air bubbles) rather than harmonising colour. Both are preprocessing, and both belong before modelling.

Why it matters for my work

The effect is now measured in-house rather than assumed, and the numbers are large. PinkKidney is a 356-slide, three-scanner cohort — 3DHistech (175 slides), Leica Aperio (95) and Hamamatsu (86) — and it quantified the batch effect directly. From 91 HistoQC slide descriptors, the acquisition group is recoverable by unsupervised clustering at kNN accuracy 0.968 (per-group recall 0.994 / 0.929 / 0.952), with 67% of descriptors significant after Bonferroni correction and 47 showing a large eta-squared. At the raw-descriptor level the acquisition signal swamps the biology: silhouette 0.121 for scanner group against 0.016 for diagnosis, a signal-to-batch ratio of 0.13.

Three lessons from that cohort transfer to any multi-scanner work here.

Design the cohort so the confounds are separable. In that cohort each vendor was used at exactly one magnification — 3DHistech at 20×, Aperio at 40×, Hamamatsu at 38× — so scanner and magnification are perfectly collinear and no analysis can separate them. That is not a processing mistake; it is a property of how the slides were acquired, and it is unfixable after the fact. Where a mixed-scanner cohort is being assembled deliberately, scanning some slides on more than one platform costs little and makes the effect estimable.

Check whether the confound aligns with the outcome, which is the part that actually matters. In that cohort it does not: both diagnoses appear on all three scanners, roughly 13/7/9 and 12/2/4. A batch effect that is balanced across the label is a nuisance; one that correlates with it is fatal. The check is a two-way table and takes a minute.

Validate the detector before trusting the verdict. That project injected a synthetic batch effect into two artificial sites — 50 of 91 descriptors shifted by 0.5 SD — and confirmed its detector recovered it at kNN accuracy 0.994. A confound screen without a positive control cannot distinguish “no batch effect” from “no working detector”.

The group runs at least two scanner platforms — Leica scanners feeding Sectra — so multi-scanner variation is a live in-house condition, not a hypothetical. It is also a stated concern in HER2 Intratumoral Heterogeneity, where fixation variability is named as one of three reasons gastric HER2 scoring is harder than breast.

On the QC side the tooling is already in place: QuPath Tooling includes HistoQC for slide-level QC whose outputs are used as QuPath-project filters, plus grandQC_quality_study and PathProfiler. The shared-resources notes also mention stain normalisation among the QuPath script utilities. [unverified] — no specific normalisation method is documented as the house standard.

How it connects

External Validation — this is the concrete mechanism that makes internal validation optimistic, and the reason an external cohort is the real test.

Foundation Models in Pathology — encoders pretrained across many institutions are usually argued to be more robust to this. That claim needs narrowing: Khan et al. 2026 found UNI-2 tile embeddings shifted substantially under staining variation and under all eight normalisation methods tested, so a foundation model does not make the problem go away.

Stain Normalisation — the technique page: which method to pick, why the simplest one often wins, and why no single method fixes both over- and under-staining.

Labquality EQA Staining Dataset — a free public dataset that isolates the stain half of this page’s two variance sources: one tissue block, 66 laboratories, one scanner.

Ki-67 Proliferation Index — the same between-laboratory staining problem, but for an IHC stain rather than H&E: Shaaban 2026 (sources/papers/shaaban-2026-uk-ki67-recommendations.md) treats Ki-67 reproducibility as a between-lab property to be audited through an EQA scheme (UK NEQAS), which is the same logic as the Labquality round above applied to a diagnostic marker instead of routine H&E.

WSI Quality Control — the pipeline that detects the artefact side of the problem.

Whole Slide Imaging — scanner and magnification are recorded in WSI metadata, which is how you would audit this in the first place.

Nottingham Grading — adds a third variance source to the two on this page: the display. Monitor, calibration, and on-screen field size affect nuclear pleomorphism scoring and high-power field calibration, and unlike scanner and stain this one sits between the image and the human rather than between the tissue and the image.

Persistent Homology — a worked instance of the same dependency in a derived feature: its scale parameter is a distance in pixels, so a topological descriptor tuned at one magnification silently means something else at another.

Feature-Space Distance — the instrument for this page’s subject: it turns “the feature cloud moved” into a normalised number, with a floor that says how much movement is just finite-sample noise. Use a sensitive encoder for it, since the robust ones are built to not notice.

Federated Learning in Pathology — this page’s phenomenon distributed across institutions. It is the non-IID problem, and it is what makes averaging models across hospitals hard rather than routine; federated stain normalisation exists precisely because of it.

Colour Calibration — the upstream alternative to correcting any of this in software: fix colour physically at the scanner against a reference target. It is the one intervention with published evidence of moving AI agreement across sites, and it acts before every modelling choice on this page is made.

Open questions

  • Is any stain normalisation currently applied in the group’s AI pipelines? Answered for one project. PinkKidney runs Macenko, grayscale conversion, per-channel z-scoring and ComBat batch correction as explicit comparison arms. No house standard follows from it yet, because the comparison could not be ranked — see Stain Normalisation.
  • Are cohorts for the AI projects single-scanner or mixed? Answered for one project, and the answer is mixed: PinkKidney spans three vendors, records vendor and magnification per slide in cohort_metadata.csv, and has run the confounding-with-outcome check. The question stands unanswered for Liver Tru-Cut — Tumour Origin AI, Paige Prostate and Aiforia Breast, and the PinkKidney metadata script is the obvious thing to point at those cohorts.
  • A scanner-swap experiment (same slides, both scanners) would quantify the effect directly and is feasible in-house. It is now also the only way to separate scanner from magnification in PinkKidney, where the two are perfectly collinear by construction — re-scanning even a handful of slides on a second platform would break the collinearity for those cases.
  • Does the acquisition effect measured on raw slide descriptors actually survive into a foundation-model feature space? Partly answered: it shrinks sharply but does not vanish — signal-to-batch moves from 0.13 on HistoQC descriptors to 1.79 on UNI features, and ComBat still finds magnification structure to remove. See Foundation Models in Pathology.