FewRef-5: Fixed-Reference Test-Time Adaptation for Virtual Staining
Organizations: Anhui Provincial Key Laboratory of Secure Artificial Intelligence, Anhui Provincial International Joint Research Center for Advanced Technology in Medical Imaging, School of Artificial Intelligence, Anhui University, Hefei 230093, China.
Abstract
Virtual staining synthesizes special-stain images from routine hematoxylin and eosin (H&E), extending the information available from an existing digital slide. However, a fixed inference rule can leave available real target-stain references unused, limiting query-specific correction of stain appearance at deployment. Test-time adaptation (TTA) provides a mechanism for this reference-guided, query-specific refinement without retraining the generator. We therefore propose FewRef-5, a reference-assisted TTA method for virtual staining built on StainPromptInversion. We extract tissue-masked optical-density means and standard deviations from five real Masson's trichrome (MAS) training patches and average them into a fixed stain target. A scheduled statistic-matching loss introduces this target into per-query visual-prompt optimization alongside our edge/Gram consistency penalties and the inherited reconstruction objectives. The target remains unchanged across queries, avoiding recursive dependence on earlier generated outputs while the pretrained generator stays fixed. On recorded H&E-to-MAS outputs for 1,989 queries, FewRef-5 reduces target-set FID from 183.201 to 166.904 and increases source-referenced SSIM from 0.92787 to 0.94996 relative to our Edge+Gram variant. Source PSNR and MS-SSIM decrease, showing an endpoint trade-off rather than uniformly better reconstruction.
Figures & tables
| Symbol | Definition |
|---|---|
| H&E query and source/target conditions | |
| Frozen diffusion and style-adapter parameters | |
| DDIM steps and query-specific visual prompt | |
| Real training reference set and its size | |
| Six OD statistics and fixed reference average | |
| Style/structure balance and stain-loss weight |
| Method / variant | Unpaired real MAS | Source H&E | |||
|---|---|---|---|---|---|
| FID | PSNR (dB) | SSIM | CSS | MS-SSIM | |
| Published StainPromptInversion [ 37 ] | 179.289 | 20.915 | 0.92330 | 0.93090 | 0.94580 |
| Ours (Edge+Gram) | 183.201 | 21.260 | 0.92787 | 0.93478 | 0.95486 |
| Ours (EMA memory) | 179.697 | 21.238 | 0.92830 | 0.93512 | 0.95386 |
| Ours (hard gate 0.0035) | 182.180 | 21.630 | 0.93047 | 0.93659 | 0.95483 |
| Ours (hard gate 0.0040) | 181.401 | 21.568 | 0.92992 | 0.93612 | 0.95438 |
| Method / variant | Objective or update rule |
|---|---|
| Published | Original style/structure objective; external protocol. |
| Ours (Edge+Gram) | Adds ; no OD-memory term. |
| Ours (EMA memory) | Adds OD loss; first output initializes memory, then EMA with . |
| Ours (hard gates) | Write only for non-NaN , with or . |
| Ours (soft gate) | Write weight , where . |
| FewRef-5 (ours) | Matches the mean of five real training references; generated outputs never update it. |
Virtual Staining
Virtual staining uses AI to predict histochemical or immunohistochemical appearances from unstained or differently stained tissue images.
See all 23 papers