Stain-Ratio Indices as Numeric Queries for Pathology Image Search

When a pathologist searches an archive for "a case like this one, but with more stroma," current systems have two options, and both are weak. They can rank by visual similarity in a pretrained feature space, which has no way to express "more." Or they can accept a text instruction, which is a poor medium for a quantity like "about 15 percentage points more connective tissue." This proposal borrows a device from satellite remote sensing. There, vegetation indices such as NDVI are simple normalized differences between two spectral bands, (NIR − Red)/(NIR + Red). They cancel brightness changes that affect both bands equally and leave behind a number with physical meaning. We build the analogue for stained tissue: a normalized difference between the amounts of the two stains, hematoxylin (which binds nuclei) and eosin (which binds cytoplasm and stroma), computed pixel by pixel after the image is converted to stain amounts. We then use that index in two ways. First, it becomes a numeric control knob that is combined with a reference image to form a search query, replacing the text instruction. Second, it serves as an audit that tests whether frozen pathology foundation models respond to tissue composition or to staining intensity.

In two sentences: an NDVI-style ratio of stain amounts gives a number that ignores slide thickness and overall stain dose, so users can say "like this, but with this much more epithelium" as a number rather than a phrase. We test whether this beats text-instructed composed retrieval and a naive filter, using pathologist-annotated tissue fractions as ground truth that the index itself never touches.

Core Claim

Continuous compositional attributes of tissue are poorly served by language. Rich-text work on image generation found that text encoders cannot reliably carry exact numbers or colors (Expressive Text-to-Image Generation with Rich Text). The strongest pathology system for combined image-and-text queries, HOMIE, still specifies the requested change in words (HOMIE). Our claim is that a physically motivated scalar supplies the "delta" of a composed query more precisely than text does. That scalar is the stain-ratio index, summarized over a patch.

We also claim the index is invariant to a specific and nameable set of nuisances. Under the Beer–Lambert law (light absorbed grows with stain amount along the path), each pixel's red-green-blue optical density can be separated into hematoxylin and eosin concentrations $C_H$ and $C_E$ by standard color deconvolution. Define the per-pixel index

$$h = \frac{C_H - C_E}{C_H + C_E + \epsilon},$$

where $\epsilon$ is a small constant that stabilizes pixels with almost no stain. Suppose section thickness or overall staining dose scales both concentrations by a common factor $k$. Then $h$ does not change, for the same reason NDVI cancels proportional illumination in the vineyard study that motivates this design (Karakizi et al.). That study reported cross-sensor agreement of $r^2 > 0.94$ for ratio-based measurements.

The invariance has limits, and we state them up front. The index does not cancel a differential batch shift, where one stain darkens relative to the other. It also does not cancel mis-estimated blank-glass brightness, which adds offsets in optical density rather than scale factors. Part of the research is measuring how much real site-to-site variation falls inside the invariant class and how much falls outside it.

Research Program

The system has three parts, and none requires training a large model.

Index maps. We compute the index map per patch. We then summarize it into a small vector $g(x)$ of statistics: the fraction of pixels above hematoxylin-dominant and eosin-dominant thresholds, the mean index, and a few quantiles. This mirrors how remote sensing summarizes NDVI over a field.

Frozen features. We extract features from frozen pathology foundation models such as UNI, Virchow and GigaPath, in the DeCAF tradition of reusing intermediate activations without retraining (DeCAF).

Composed query. The user supplies a reference patch $q$ and a numeric change $\Delta$ in one index statistic. The score for a candidate $x$ is

$$s(x) = \cos\big(f(x), f(q)\big) - \lambda \,\big\| g(x) - g(q) - \Delta \big\|^2,$$

where $f$ is the frozen feature map, $\cos$ is cosine similarity, and $\lambda$ trades appearance similarity against hitting the numeric target. We also test a second variant that moves the query inside feature space. There, a linear probe from $f$ to $g$ defines a direction, and we search around $f(q)+\alpha w$, where $w$ is the probe direction and $\alpha$ is chosen to produce the requested $\Delta$. This is the retrieval counterpart of the unsupervised editing directions in NoiseCLR (NoiseCLR). Our directions are supervised by a physical quantity, which avoids NoiseCLR's dependence on whatever the base model happens to encode.

We keep retrieval at patch level on a Yottixel-style mosaic. The reason is that whole-slide embeddings were shown to wash out focal findings, with heterogeneous organs falling to about 21% (Validation of histopathology foundation models through whole slide image retrieval).

Audit. Separately, we measure how much each foundation model's embedding moves under two kinds of perturbation. The first kind leaves the index unchanged: common concentration scaling and brightness scaling. The second kind changes the index: differential stain shift and synthetic changes in tissue composition. A model that reacts more to the first kind than to the second is keying on staining rather than tissue. The NCT-CRC-HE analysis gives concrete reason to suspect this. It showed color histograms alone reaching 82.2% accuracy on a standard benchmark (NCT-CRC-HE).

Baselines

Naive reference points. The "do nothing" reference is pure visual nearest-neighbor search on frozen UNI features, which ignores $\Delta$ entirely. It tells us how often the requested change is satisfied by accident. The closest published number for this system is from Alfasly et al., who report Yottixel-UNI at 42% ± 14% top-5 macro F1 and 44% top-1 F1 for TCGA slide retrieval (Validation of histopathology foundation models). That task is different from ours, so we rerun it on our query sets rather than compare against the figure.

Strongest existing method. The strongest competitor is text-instructed composed retrieval with HOMIE (HOMIE). It is the only system in the file built for reference-plus-modification queries in pathology, and it reports 78.5% R@1 on multi-image-to-text composed retrieval. We found no reported result on Lacuna for numeric-attribute composed retrieval in pathology, so we construct that benchmark ourselves. HOMIE receives the same reference patch plus a templated instruction carrying the same quantity ("similar tissue with roughly 20% more stroma"). We try several phrasings and report its best one, which gives the text interface an equal tuning budget. The same number is also given to CONCH as a dual-encoder text baseline.

Filter-then-rank. This baseline computes $g$ for every database patch, keeps the patches whose statistic falls within tolerance of $g(q)+\Delta$, and ranks the survivors by UNI cosine similarity. It is the obvious simpler way to use the index, and it isolates whether our scoring or feature-space direction adds anything beyond thresholding.

Normalization ablation. To isolate the ratio itself, we replace $g$ with the same statistics computed on raw deconvolved $C_H$ and $C_E$ without normalization, and separately on Macenko-normalized RGB.

All methods search the same database, use the same frozen backbone where a backbone applies, and have their few hyperparameters selected on the same held-out validation queries. Beating the baselines means a higher rate of retrieved patches that are both relevant and on target, at matched ranks, with confidence intervals that do not overlap. It also means holding that advantage on the site-shifted split.

Why not just…?

Why not just write the number into a text prompt for HOMIE or CONCH? This is the main threat, and the experiment is built to settle it. The rich-text study found text encoders unreliable for exact quantities (Rich Text), but that finding comes from natural-image generation. A pathology language model tuned on reports might handle "more stroma" coarsely. If HOMIE matches our method at coarse changes but not at fine ones (for example 5 versus 20 points), the claim narrows to fine-grained control. If it matches everywhere, the text interface is adequate and we will report that.

Why not just color-normalize with Macenko or Reinhard and use the normalized features? Normalization maps each slide toward a template. It does not produce a quantity that is invariant by construction. The NCT-CRC-HE analysis documents normalization pipelines that introduced corrupted dynamic range, which models then exploited (NCT-CRC-HE). The normalization ablation measures this directly on our site-shifted split.

Why not just filter by the index and skip the feature-space machinery? This may well win. A cheap filter could be all a clinician needs, which is why it is a baseline rather than a strawman. The learned direction justifies itself only if it keeps morphological similarity to the reference higher at the same target accuracy. We measure that by the rate at which retrieved patches match the reference's tissue class.

Why not trust foundation models, already trained with stain augmentation, to be invariant? Their ceiling below 50% macro F1 across TCGA suggests unresolved confounds (Validation of histopathology foundation models), but it does not prove stain sensitivity. The audit answers this empirically. If the embeddings turn out insensitive to index-preserving perturbations, the invariance half of the proposal is unnecessary and only the query interface remains.

Proposed Experiments

Composed-retrieval benchmark. The central benchmark uses the Stanford Tissue Microarray breast regions, which carry pathologist epithelium and stroma masks (BrcaSeg). Ground-truth stromal fraction comes from the masks, never from the index, so the evaluation is not circular. For each query we sample a reference and a target change. A retrieved patch counts as correct if its annotated stromal fraction lies within a tolerance of the target and it comes from the same diagnostic category. We report precision at 1, 5 and 10 against the size of the requested change.

Slide-scale check on TCGA-BRCA. A second check applies the method to TCGA-BRCA slides. We test whether index-steered retrieval moves from ER-positive-like toward triple-negative-like composition, since the BrcaSeg segmentation found mean stromal ratios of 72.8% for ER-positive tumors and mean epithelial ratios of 63.56% for triple-negative tumors. Retrieval is scored against receptor status. The segmentation-derived ratios serve only as context.

Invariance audit. The audit runs on NCT-CRC-HE-100K, with evaluation on CRC-VAL-HE-7K. We train linear probes on index-map statistics and compare them with the published color-histogram (82.2%) and ImageNet-feature (92.2%) references (NCT-CRC-HE). We repeat under JPEG quality 20, where that paper reported drops of up to 8.8% for DeepCMorph against about 1–2% for EfficientNet-B0. We also measure embedding displacement for UNI, Virchow and GigaPath under index-preserving versus index-changing perturbations.

Decisive checks. The first decisive check is whether our score beats HOMIE with its best-worded numeric prompt on changes of 10 points or less, on patches held out by acquisition site. The second is whether the real TCGA site-to-site color variation is mostly common-scaling, which the index removes, or mostly differential, which it does not. We estimate this by fitting the scale-versus-shift decomposition of deconvolved concentrations across sites. If the variation is mostly differential, the vegetation-index analogy is weaker than it looks, and the paper will say so.