ScanGen: Mitigating Scanner Bias in Pathology
- ScanGen is a contrastive loss function that addresses scanner bias by aligning embeddings from the same specimen scanned on different devices.
- It employs a lightweight three-layer projection network to balance attraction and repulsion, preserving discrimination between specimens.
- Experimental results show improved EGFR mutation prediction and reduced coefficient of variation across scanners in multiple pathology foundation models.
Searching arXiv for “ScanGen” and closely related papers to ground the article in current literature. ScanGen is a contrastive loss function for mitigating scanner bias in computational pathology pipelines built on pathology foundation models (FMs). It is introduced in the context of multiple instance learning (MIL) for Whole Slide Images (WSIs), where pretrained frozen FMs are used as patch-level feature extractors and downstream aggregators operate on embedding sequences rather than raw image pixels. The central premise is that scanner-induced variation can alter model representations and predictions for the same specimen even when the underlying tissue is unchanged. ScanGen addresses this by learning an embedding-space projection that aligns the same specimen across scanners while preserving discrimination between different specimens scanned by the same device (Carloni et al., 29 Jul 2025).
1. Definition and problem setting
In digital pathology, the same glass slide may be digitized by different scanners, and those scanners differ in optics, illumination, sharpness, contrast, compression, and proprietary image processing. The resulting variation can induce scanner bias, defined operationally as disagreement in model predictions for the same specimen scanned by different devices (Carloni et al., 29 Jul 2025). This issue is especially salient in WSI pipelines that rely on pretrained pathology FMs as frozen feature extractors, because classical image-level style normalization methods are less directly applicable once the downstream system operates on embeddings rather than pixels.
The downstream formulation considered with ScanGen is standard MIL. A slide is partitioned into patches , a pretrained frozen foundation model extracts patch embeddings
and an aggregator with classifier produces a slide-level prediction
Within this setting, ScanGen is inserted before aggregation by introducing a learnable projection network , so that the MIL aggregator operates on projected embeddings rather than raw FM outputs: This makes ScanGen neither a new foundation model nor an image normalization procedure. It is an embedding-space regularizer applied during downstream task-specific fine-tuning (Carloni et al., 29 Jul 2025).
The motivating application in the paper is Epidermal Growth Factor Receptor (EGFR) mutation prediction from H&E-stained WSIs in lung cancer using MIL. The broader claim is that scanner sensitivity persists even in modern pathology FMs and must therefore be addressed explicitly rather than assumed to vanish through large-scale pretraining (Carloni et al., 29 Jul 2025).
2. Scanner bias and its measurement
A distinctive aspect of the ScanGen framework is that scanner bias is benchmarked using same-specimen-across-scanner comparisons rather than only aggregate predictive accuracy. If specimen is scanned by scanners , the model produces logits 0. Scanner sensitivity is then quantified by the average coefficient of variation (CoV) across scanners: 1 where 2 is the number of specimens, and 3 and 4 are the standard deviation and mean over scanner-specific logits for the same specimen (Carloni et al., 29 Jul 2025).
Lower CoV indicates better agreement and less scanner sensitivity. The paper prefers CoV over raw standard deviation because it normalizes by the prediction scale. This metric is complemented by magnification CoV across 40× and 20× scans, EGFR AUC on held-out test data, and UMAP visualization of WSI embeddings averaged over patches (Carloni et al., 29 Jul 2025).
This benchmark design is unusually strong because it disentangles scanner nuisance variation from biological variability. A plausible implication is that ScanGen should be interpreted less as a generic regularizer than as a response to a specifically instrumented deployment problem: identical tissue can induce materially different predictions solely because of acquisition hardware differences.
3. ScanGen objective and pair construction
The ScanGen loss is defined from two terms: an attraction term and a repulsion term. The attraction term pulls together embeddings of the same specimen scanned by different scanners. The repulsion term pushes apart embeddings of different specimens scanned by the same scanner. Given two specimens 5 and 6, and two scanners 7 and 8, the loss is
9
with cosine distance
0
The repulsion term is a squared hinge-margin form that is active only when different-specimen same-scanner pairs are closer than margin 1 (Carloni et al., 29 Jul 2025).
The positive and negative pair semantics are central. Positive pairs are 2, meaning same specimen and different scanners. Negative pairs are 3, meaning different specimens but the same scanner. This differs from ordinary contrastive learning, where negatives are often all other samples. Here the negatives are deliberately restricted to share scanner identity, so the projection network cannot minimize the objective by clustering samples by scanner domain (Carloni et al., 29 Jul 2025).
Three hyperparameters govern the behavior of the loss. The balance parameter 4 trades off attraction and repulsion, 5 defines the repulsion margin, and 6 weights ScanGen relative to the downstream classification loss. The reported practical ranges are 7: 8 to 9, 0: 1 to 2, and 3: 4 to 5 (Carloni et al., 29 Jul 2025).
This structure makes ScanGen a scanner-aware contrastive regularizer rather than a standard self-supervised objective. It is supervised by specimen identity and scanner metadata, and its pair construction explicitly encodes the invariance target.
4. Integration into MIL-based pathology pipelines
The full training objective combines cross-entropy for EGFR prediction with the ScanGen loss. Although the typesetting of the complete formula is truncated in the paper, the intended combined objective is explicitly described as a sum of the downstream EGFR classification loss and the ScanGen contrastive term over valid specimen/scanner combinations (Carloni et al., 29 Jul 2025).
Operationally, training contains two independent branches per step. The first is the EGFR branch, which performs an ordinary MIL forward pass on EGFR-labeled slides through the projection 6, aggregator 7, and classifier 8, optimized with cross-entropy. The second is the ScanGen branch, which takes embeddings indexed by specimen and scanner identity, passes them through 9, and computes the attraction and repulsion terms using in-batch pairwise cosine distance, same-scanner masks, and same-specimen masks (Carloni et al., 29 Jul 2025).
The architecture is intentionally lightweight. The foundation model 0 remains pretrained and frozen. The projection network 1 is a 3-layer MLP, with hidden dimension between 48 and 96 depending on FM features. The default aggregator 2 is global average pooling, though ScanGen is also evaluated with AB-MIL, DS-MIL, and SlotMIL. The classifier 3 is an MLP (Carloni et al., 29 Jul 2025).
This design is important because it targets a practical deployment regime in which retraining the backbone FM is computationally expensive or infeasible. ScanGen instead modifies the representation interface between a frozen FM and a downstream MIL head. A plausible implication is that its main contribution is infrastructural compatibility: it can be layered on top of existing FM-based WSI systems without replacing the backbone.
5. Experimental setting and quantitative findings
The downstream EGFR branch is trained using two public datasets, CPTAC and TCGA, selecting only non-small cell lung cancer specimens, for a total of 1,144 WSIs (Carloni et al., 29 Jul 2025). The scanner-generalization benchmark uses a dedicated multi-scanner dataset of 323 specimens, each tested for EGFR mutation via PCR and NGS assay, scanned by six scanners at 40×—Leica Aperio AT2, Leica Aperio GT450, Hamamatsu Nanozoomer S360MD, 3DHistech P1000, Philips UFS B300, and Roche Ventana DP200—plus the same specimens scanned by Leica Aperio GT450 at 20×, for a total of 2,261 WSIs (Carloni et al., 29 Jul 2025).
The split is done at the specimen level to avoid leakage across scanner copies: 54 specimens for training the ScanGen branch, 45 for validation/tuning of both branches, and 224 held out for test. Class balance is preserved, and all scans of the same specimen remain in the same split (Carloni et al., 29 Jul 2025).
Five frozen pathology FMs are benchmarked: Phikon, UNI, Virchow, Gigapath, and H-Optimus-0. The principal baseline is the same downstream pipeline without the ScanGen loss; importantly, the baseline still includes the projection network 4, so performance gains cannot be attributed merely to adding an extra MLP (Carloni et al., 29 Jul 2025).
The main quantitative results show that ScanGen generally improves scanner robustness while maintaining or improving EGFR AUC. For Phikon, AUC rises from 5 to 6, scanner CoV drops from 7 to 8 (9), and magnification CoV drops from 0 to 1 (2). For UNI, AUC improves from 3 to 4, scanner CoV from 5 to 6, and magnification CoV from 7 to 8. For Virchow, AUC improves from 9 to 0, scanner CoV from 1 to 2, and magnification CoV from 3 to 4. For Gigapath, AUC improves from 5 to 6, scanner CoV decreases from 7 to 8, but magnification CoV worsens from 9 to 0. For H-Optimus-0, AUC improves from 1 to 2, scanner CoV drops from 3 to 4, and magnification CoV from 5 to 6 (Carloni et al., 29 Jul 2025).
Using H-Optimus-0 features, ScanGen also generalizes across MIL heads. With GAP, AUC improves from 7 to 8 and CoV decreases from 9 to 0. With AB-MIL, AUC improves from 1 to 2 and CoV from 3 to 4. With DS-MIL, AUC drops slightly from 5 to 6 while CoV improves from 7 to 8. With SlotMIL, AUC improves from 9 to 0 and CoV from 1 to 2 (Carloni et al., 29 Jul 2025).
An ablation on the number of scanners used during ScanGen training shows that scanner robustness improves monotonically as more scanner types are included, with gains converging around five scanners. Even with only three scanners used during training, generalization on six test scanners improves by 27%. Scanner diversity also matters: best-performing combinations often include Leica Aperio GT450 and Hamamatsu, while poor combinations often involve Leica Aperio AT2 plus GT450, which the authors interpret as evidence that more diverse scanners induce stronger invariance (Carloni et al., 29 Jul 2025).
6. Relation to adjacent “scan” research and scope of the term
The term “ScanGen” is overloaded across research domains, and the pathology method should be distinguished from several unrelated uses of “scan” terminology. In human gaze modeling, “ScanGAN360” is a conditional GAN for generating realistic scanpaths in 360° images, operating on spherical scanpath representations and spherical soft-DTW losses rather than pathology embeddings (Martin et al., 2021). In radiological search, scan statistics are used to detect, identify, and localize illicit radiological material from time-stamped gamma events, again with an unrelated probabilistic formulation (Porter et al., 2020). In scanner forensics, CNNs classify source scanner models from 3 RGB patches and produce scanner-consistency reliability maps for manipulation detection (Shao et al., 2020). In cloud segmentation, “SCANet” denotes the Segregation and Context Aggregation Network, a lightweight binary segmentation architecture rather than a pathology robustness method (Li et al., 19 Apr 2025). In document retrieval-augmented generation, “SCAN” refers to SemantiC Document Layout ANalysis, a coarse-grained semantic layout detector for rich-document RAG rather than a foundation-model regularizer (Dong et al., 20 May 2025).
These neighboring usages clarify the specificity of pathology ScanGen. It does not generate scans, scanpaths, or semantic regions. It also does not refer to scanner source attribution in the forensic sense. Its target is scanner invariance of downstream pathology predictions under frozen FM embeddings (Carloni et al., 29 Jul 2025).
This distinction matters because a superficial reading of the name could suggest synthetic scan generation or generic scanner normalization. The paper instead defines a narrowly scoped intervention: paired multi-scanner supervision in embedding space to reduce WSI prediction instability.
7. Limitations, assumptions, and significance
ScanGen depends on paired multi-scanner WSIs of the same specimen, or at least enough metadata to know which slides correspond to the same specimen and which scanner acquired them (Carloni et al., 29 Jul 2025). This is both a strength and a constraint. It is a strength because the supervision is directly aligned with the invariance objective. It is a constraint because such datasets are expensive and uncommon.
The method mitigates scanner bias only at the embedding/projection level and does not retrain the FM itself. Results are demonstrated for a single downstream clinical task, EGFR mutation prediction in lung cancer. Gains are not uniform across all backbones and metrics, with Gigapath showing only modest scanner CoV improvement and worsened magnification CoV. The paper also omits several practical reproduction details, including optimizer type, learning rate, batch size, number of epochs, patch count per slide, exact feature dimensions per FM, and computational runtime (Carloni et al., 29 Jul 2025).
Despite these limitations, the method has broader implications for computational pathology. The benchmark shows that pathology FMs remain scanner-sensitive even when used as frozen general-purpose feature extractors. This challenges any assumption that large-scale pretraining alone eliminates acquisition bias. The authors further frame scanner sensitivity as a deployment and fairness issue because scanner brands are unevenly distributed geographically, making scanner-specific performance variation a potential source of site-dependent inequity (Carloni et al., 29 Jul 2025).
Taken together, ScanGen establishes two linked claims. First, pathology foundation models can encode scanner-specific nuisance variation strongly enough to alter predictions for the same specimen. Second, a lightweight projection-head-based contrastive loss, using scanner-aware and specimen-aware pair construction, can materially improve scanner agreement while preserving or improving downstream task performance (Carloni et al., 29 Jul 2025). This suggests that scanner robustness in foundation-model-based computational pathology may be better treated as a representation-alignment problem than as a purely image-normalization problem.