Exemplar-based counters are one of the most practical tools computer vision offers pathology. These are "class-agnostic" counters: the user draws a box around two or three examples of something, and the model counts every similar object in the image, without being trained on that category. A pathologist could box a few mitotic figures or lymphocytes and get a count, with no dataset collection and no retraining. Slides, however, are digitized on different scanners at different hospitals. The same glass slide scanned on a Leica and on a 3DHISTECH machine yields images that differ in sharpness, contrast, color, and background handling. Segmentation models lose up to 0.38 mIoU across scanners on identical tissue (Multi-Scanner Canine Cutaneous Squamous Cell Carcinoma Histopathology Dataset). Nobody has measured what these shifts do to exemplar-based counters, or whether a count taken at one site can be trusted at another.
We propose to measure this and to fix it with one training signal that is cheap and does not depend on the object category. When the same physical tissue region has been scanned on several machines and registered, any exemplar-defined object must have the same count in every scan, and its similarity map, meaning the per-pixel "looks like the exemplar" response, must land in the same place. That constraint needs no labels and no category names. It applies to whatever the user might later box. We will train counters to satisfy it at the level of the task output: the similarity map and the integrated count. We deliberately avoid enforcing it on backbone features, because feature-level alignment has already been shown to do little for the downstream task.
Core Claim
Our claim has two parts. The first is diagnostic. For exemplar counters, scanner shift should matter much less when the exemplars come from the same scan as the query, because both then share the same optical signature. It should matter much more when exemplars are reused across scanners, for example a reference cell type defined once at a central lab and applied to slides from other hospitals. It should also matter when the backbone itself degrades on unfamiliar optics, such as the pure-white backgrounds produced by the Pannoramic 1000. We expect current counters trained on natural images to show a modest gap in the first protocol and a large one in the second.
The second part is the method. Consistency across registered scans of the same tissue, applied to similarity maps and counts, closes the cross-scanner gap on scanners held out from training. It should do so better than aligning features, and better than consistency under synthetic scanner-like augmentations. If synthetic augmentations work equally well, the real ingredient is output-level consistency, and physical paired scans are not needed. The experiments are designed to separate these two explanations. We will report whichever outcome holds.
What Prior Work Establishes and Leaves Open
Several papers motivate the gap. Single Domain Generalization for Few-Shot Counting via Universal Representation Matching (URM) shows that counters trained on FSC147 build rigid prototypes that fail out of distribution. Its fix distills CLIP image features and GPT-4 text descriptions of each class into the prototype extractor, reaching MAE 21.87 against 25.11 for MPCount on FSCD-LVIS. Its shifts are between natural-photo datasets, however, and its language anchors assume nameable classes. We target the case where the class is defined only by the boxes and the shift is optical. Mind the Gap supplies both the setting and a key negative result. The same authors built the five-scanner, co-registered canine carcinoma dataset (CATCH). Using it, they found that Barlow Triplets alignment of embeddings across scanners shrank feature distances but moved unseen-scanner mIoU only from 0.78 to 0.79. They attribute part of the failure to low-level scanner noise leaking through U-Net skip connections. We read this as ruling out feature-level invariance as the main lever, which is why our consistency acts on what the counter actually outputs.
Microscopy counting has been adapted across domains before, but never with class-agnostic models. Cross-domain Microscopy Cell Counting by Disentangled Transfer Learning separates density from style. It reaches MAE 6.2 versus 18.1 on bone marrow, but only after GAN synthesis and fine-tuning on 2 to 10 annotated target images. Automatic microscopic cell counting by use of unsupervised adversarial domain adaptation and supervised density regression aligns real stem-cell features to synthetic ones with a Wasserstein critic, cutting MAE from 170.06 to 35.82. Both methods are single-category regressors that need target-domain data. Our method is exemplar-conditioned and never sees the test scanner. CellFMCount supplies a fluorescence benchmark and SAM-Counter (MAE 22.12, ACP 48.73%). It also documents a "staining gap" across markers, which gives us a second, biological kind of shift. OCELOT acts as a constraint: cell-only detection reaches F1 64.44, and adding tissue context raises it to 71.23. Local exemplar similarity will therefore confuse tumor cells with stroma regardless of scanner, and we must not mistake that error for scanner shift.
We reuse the counting machinery itself. A Low-Shot Object Counting Network With Iterative Prototype Adaptation (LOCA) builds separate shape and appearance queries from the exemplars and refines them against the image. It reports FSC147 RMSE 56.97 and CARPK MAE 9.97, and it is our base architecture. Learning To Count Everything (FamNet, FSC147 MAE 22.08) contributes its test-time adaptation on exemplars as a baseline. Few-shot Object Counting with Similarity-Aware Feature Enhancement (SAFECount) and the training-free CountingDINO widen the spread of architectures we measure.
Research Program
The first component is a benchmark: a counting layer on top of CATCH. CATCH has tissue polygons but no cell points. We will annotate nuclei centroids, split by type into tumor, inflammatory, and other, on a set of regions from one reference scanner. We will then transfer the points to the other four scanners using the same slide registration Wilm et al. used for polygons, and manually check a subset for registration error. Splits are made by tissue sample, so test tissue is never seen in training.
We define two evaluation protocols. In the same-scan protocol, exemplars are drawn from the query image. In the cross-scan protocol, exemplars are drawn from the co-registered region on a different scanner, or from a different slide on a different scanner. Beyond count error, we report the coefficient of variation of the predicted count for the same region across its five scans. This is a reproducibility number a clinician would actually ask for.
The second component is the training objective. Let $x_a$ and $x_b$ be registered scans of the same region from scanners $a$ and $b$, and let $E$ be exemplar crops, sampled either as random repeated structures or as annotated cells. Let $S(x, E)$ be the counter's similarity map and $\hat{c}(x,E)$ its integrated count. We add
$$ \mathcal{L}_{\text{pair}} = \big\| S(x_a, E) - S(x_b, E') \big\|_1 + \lambda \,\big| \log \hat{c}(x_a,E) - \log \hat{c}(x_b,E') \big|, $$
where $E'$ is either the same crops re-cut from scan $b$ (same-scan consistency) or the crops from scan $a$ applied unchanged to scan $b$ (cross-scan consistency). The weight $\lambda$ balances map agreement against count agreement. The loss is added to the standard density loss on FSC147 and on whatever labeled scanner-a regions exist. The log form makes count disagreement relative, which suits counts ranging from tens to hundreds. The loss needs no labels on scan $b$, so any registered slide pair can be used.
We train with three scanners (Aperio CS2, NanoZoomer S210, NanoZoomer 2.0-HT) and hold out Pannoramic 1000 and Aperio GT 450. These two show the white-background clipping and the sharpness/contrast inversion that Wilm et al. identify as the hardest shifts.
The third component is analysis. We will separate how much of the cross-scan error comes from the exemplar prototype and how much from the query features. To do this, we swap exemplars and queries between scanners independently. We will also check whether errors concentrate in stroma, in the OCELOT sense, or in background and debris, in the Pannoramic 1000 sense.
Baselines
The do-nothing reference is LOCA trained on FSC147 and applied directly to each scanner under both protocols. It fixes the size of the gap. No reported result was found on Lacuna for any class-agnostic counter on multi-scanner histopathology, so this measurement is itself new.
The strongest existing domain-generalization competitor is URM. It is the only published method built for exactly this train-on-one-domain regime, with MAE 21.87 on FSCD-LVIS in its paper. We will run it with its own recipe on the same FSC147 plus CATCH training data. For the language branch we use generic descriptions of the cell types we can name. This is its best case: it tests whether language anchors help in pathology at all.
The strongest non-exemplar reference is SAM-Counter, which reports MAE 22.12 on CellFMCount. We will fine-tune it on the labeled training-scanner regions under the same annotation budget. It shows what a supervised, class-specific model achieves, and how far a class-agnostic model falls short of it or exceeds it.
Every method gets the same training scanners, the same labeled regions, the same backbone initialization where applicable, and the same hyperparameter search budget, selected on a validation split from the training scanners only.
Three ablations isolate the ingredient we claim matters:
- Feature-level alignment. A Barlow Triplets-style loss on LOCA's backbone features over the same paired scans. This tests whether where the consistency acts matters.
- Synthetic-pair consistency. The identical output loss, but with $x_b$ generated from $x_a$ by random sharpness, contrast, color, white-background clipping, and JPEG compression. This tests whether physical pairing matters.
- Count-only consistency. The $\lambda$ term without the map term.
Beating the field means lower MAE and lower cross-scan coefficient of variation on both held-out scanners than the best of these, under the cross-scan protocol, with no loss on the same-scan protocol, and averaged over at least three seeds with sample-level bootstrap intervals.
Why not just…?
Why not just stain-normalize before counting? Normalization aligns color statistics. The CATCH study shows that scanner shift also involves sharpness, contrast, and background clipping on identically stained slides, and still costs up to 0.38 mIoU. We will run Macenko-style normalization and the adaptive normalization of Adaptive Stain Normalization for Cross-Domain Medical Histology in front of plain LOCA. If this closes most of the gap, the problem is mostly color, and our loss is unnecessary. We would report that outcome as the finding.
Why not just use heavy scanner-like augmentation? This is the real threat, and it is why the synthetic-pair ablation exists. If simulated sharpness, contrast, and clipping reproduce the gains of real pairs on the held-out scanners, the lesson is "enforce output consistency under realistic augmentation." Physical multi-scanner data would then be unnecessary. That would be a cheaper and more broadly useful result, and we would say so.
Why not just align features across scanners? Barlow Triplets already did this on the same slides and moved unseen-scanner mIoU only from 0.78 to 0.79 (Mind the Gap). Exemplar matching compares features at many scales, which invites the same leakage. The feature-level ablation tests directly whether output-level consistency does better under identical data.
Why not just adapt at test time on the exemplars, as FamNet does? Adapting on two or three boxes from the query image cannot see the other scanner. It also tends to push up density on look-alike stroma, the confusion OCELOT quantifies. We will run FamNet-style adaptation on top of LOCA as a baseline, and additionally in combination with our loss, since the two are compatible.
Decisive Experiments
Four results decide the proposal:
- Where the gap lives. First, the size of the gap under each protocol. If same-scan error on held-out scanners is already close to in-domain error, the practical problem lies only in cross-scan reuse and backbone degradation, and the paper narrows to those.
- Pairing or just consistency. Second, real-pair consistency against synthetic-pair consistency on Pannoramic 1000 and GT 450. This settles whether paired digitization is the ingredient.
- Location of the consistency. Third, output-level against feature-level consistency. This tests whether Wilm et al.'s negative result reflects where invariance was imposed or a deeper limit.
- Transfer to a different shift. Fourth, zero-shot transfer of the CATCH-trained counter to CellFMCount under cross-marker exemplars (DAPI exemplars applied to GFAP fields, and the reverse), plus a check on OCELOT that the gains do not come with worse tumor-versus-stroma confusion. This shows whether consistency learned from optical shift carries over to biological staining shift, or stays specific to scanners.
References
- Multi-scanner Canine Cutaneous Squamous Cell Carcinoma Histopathology Dataset
- Single Domain Generalization for Few-Shot Counting via Universal Representation Matching
- Mind the Gap: Scanner-Induced Domain Shifts Pose Challenges for Representation Learning in Histopathology
- Cross-domain Microscopy Cell Counting by Disentangled Transfer Learning
- Automatic microscopic cell counting by use of unsupervised adversarial domain adaptation and supervised density regression
- CellFMCount: A Fluorescence Microscopy Dataset, Benchmark, and Methods for Cell Counting
- OCELOT: Overlapped Cell on Tissue Dataset for Histopathology
- A Low-Shot Object Counting Network With Iterative Prototype Adaptation
- Learning To Count Everything
- Few-shot Object Counting with Similarity-Aware Feature Enhancement
- CountingDINO: A Training-free Pipeline for Class-Agnostic Counting using Unsupervised Backbones
- Adaptive Stain Normalization for Cross-Domain Medical Histology