Medical image segmentation models face recurring domain shifts that often require costly additional expert annotations and model retraining. Thus, a technique that enables a single annotated reference image to guide medical segmentation across datasets without further training is highly desirable. However, such an approach remains challenging because biomedical structures exhibit substantial intra-class feature heterogeneity and inter-class ambiguity, making typical single-prototype representations and foreground-only matching approaches insufficient. Additionally, sparse reference annotations and variations in imaging protocols further complicate this process. To address these, we introduce MedIC, a training-free framework built on the insight that reliable reference-to-target matching requires preserving diverse intra-class features while contrasting competing foreground and background evidence. Using a DINOv3 encoder pre-trained on natural images, MedIC constructs diverse foreground and background reference prototypes, contrasts their affinities to target image patches, consolidates target image features through self-similarity, and determines segmentation using target-adaptive thresholds and prototypes. Across 22 datasets spanning 10 imaging modalities and 10 segmentation tasks, MedIC achieves the highest mean Dice among evaluated methods in all tested reference annotation types (sparse, partial & full). On 11 in-distribution datasets, partial masks retaining labels for 20% of foreground patches yield 80.52% mean Dice, approaching 80.97% with full masks, while a single fully annotated in-distribution reference achieves 81.93% across 11 unseen, out-of-distribution datasets, all without medical training or adaptation. These results reveal the potential of pre-trained visual representations for efficient and generalizable medical image segmentation.
Overall MedIC pipeline. Given a frozen DINOv3 encoder and one annotated reference image, MedIC builds class-wise reference multi-prototype banks, propagates target patch features on a similarity graph, computes foreground–background contrast, and predicts the target mask via adaptive label selection.
Feature variation within medical foreground regions. PCA visualizations of DINOv3 features reveal different patterns within each annotated structure, motivating multiple reference prototypes rather than a single average feature.
Foreground–background contrast at ambiguous medical boundaries. DINOv3 foreground and background affinity maps (top and middle rows) illustrate how their difference (bottom row) suppresses shared responses (green: ground-truth contours; magenta: similarity-derived contours).
We evaluate MedIC across 22 datasets spanning 10 imaging modalities and 10 segmentation tasks (11 in-distribution datasets and 11 unseen out-of-distribution datasets) averaged over three fixed reference seeds using one reference image per dataset and a frozen DINOv3 ViT-L/16 encoder. Results below report Dice Similarity Coefficient (DSC (%)), where † denotes baselines equipped with the DINOv3 ViT-L/16 visual backbone.
Mean DSC (%) across 11 in-distribution (ID) datasets with one reference image under each annotation type. Best results are in bold and second-best results are underlined.
| Method | Points | Boxes | Scribbles | Partial Mask | Full Mask |
|---|---|---|---|---|---|
| Supervised In-context Segmentation | |||||
| UniverSeg | 13.61 | 32.36 | 5.08 | 21.91 | 39.57 |
| MultiverSeg | 15.75 | 50.16 | 0.06 | 7.28 | 63.75 |
| Tyche | 5.45 | 43.79 | 0.91 | 9.59 | 55.03 |
| Painter | 36.70 | 38.18 | 36.93 | 37.73 | 37.32 |
| SegGPT | 6.75 | 45.88 | 0.47 | 1.72 | 66.81 |
| SegIC | 39.81 | 36.05 | 41.87 | 40.91 | 40.50 |
| SINE | 43.68 | 41.95 | 48.56 | 44.78 | 44.54 |
| DiffewS | 47.08 | 42.67 | 49.58 | 49.66 | 53.67 |
| SAM-based In-context Segmentation | |||||
| GF-SAM | 66.27 | 53.53 | 65.19 | 68.56 | 67.72 |
| GF-SAM† | 66.11 | 52.93 | 62.87 | 67.58 | 67.00 |
| Per-SAM | 39.87 | 37.09 | 41.70 | 40.38 | 40.73 |
| ProtoSAM | 34.44 | 57.43 | 25.84 | 39.54 | 63.44 |
| ICL-SAM | 20.86 | 43.94 | 11.07 | 30.45 | 55.67 |
| Matcher | 62.52 | 52.63 | 63.21 | 62.48 | 61.93 |
| Matcher† | 68.16 | 56.61 | 68.51 | 68.33 | 67.51 |
| MAUP | 43.42 | 44.51 | 42.81 | 46.44 | 53.20 |
| M2C | 25.24 | 32.50 | 12.05 | 0.45 | 36.42 |
| Training-free In-context Segmentation | |||||
| INSID3 | 62.70 | 54.98 | 52.72 | 58.69 | 69.65 |
| MedIC (Ours) | 75.20 | 65.91 | 77.16 | 80.52 | 80.97 |
One fully annotated ID reference guides segmentation of both ID and unseen OOD target images across four modality families. With zero target-domain training or parameter updates, MedIC achieves 85.49% ID mean DSC, 81.93% OOD mean DSC across the 11 unseen OOD datasets (83.67% harmonic mean DSC), leading on 10 of the 11 OOD datasets.
| Method | Breast Ultrasound | Chest X-ray | Polyp Endoscopy | Chest CT | ||||
|---|---|---|---|---|---|---|---|---|
| ID | OOD | ID | OOD | ID | OOD | ID | OOD | |
| SegIC | 23.64 | 22.26 | 47.98 | 45.93 | 31.81 | 17.61 | 34.57 | 35.70 |
| SINE | 38.31 | 35.67 | 59.57 | 54.61 | 46.64 | 24.57 | 36.58 | 41.89 |
| DiffewS | 69.61 | 67.64 | 51.04 | 47.71 | 57.56 | 28.16 | 36.97 | 43.74 |
| GF-SAM | 64.33 | 56.80 | 83.76 | 69.01 | 66.52 | 45.53 | 61.77 | 56.66 |
| GF-SAM† | 69.22 | 65.32 | 92.49 | 73.42 | 75.38 | 53.52 | 41.05 | 51.18 |
| Per-SAM | 28.99 | 28.23 | 57.44 | 51.12 | 38.98 | 16.38 | 42.22 | 43.67 |
| ProtoSAM | 70.53 | 63.19 | 67.35 | 61.52 | 74.84 | 62.52 | 62.98 | 61.81 |
| ICL-SAM | 53.79 | 42.11 | 77.92 | 77.02 | 28.00 | 21.50 | 76.91 | 82.39 |
| Matcher | 52.63 | 45.72 | 93.06 | 79.91 | 63.77 | 33.25 | 74.80 | 71.91 |
| Matcher† | 64.86 | 61.65 | 93.61 | 82.15 | 80.05 | 57.10 | 73.22 | 80.95 |
| MAUP | 42.10 | 40.75 | 72.39 | 70.39 | 57.89 | 33.16 | 70.76 | 76.62 |
| M2C | 29.72 | 18.05 | 74.72 | 66.57 | 8.44 | 4.49 | 37.97 | 35.19 |
| INSID3 | 58.85 | 54.20 | 88.90 | 82.62 | 84.47 | 66.54 | 81.81 | 81.75 |
| MedIC (Ours) | 81.16 | 79.30 | 94.02 | 88.32 | 84.50 | 72.41 | 82.27 | 85.93 |
Reference annotation budget under domain shift. ID, OOD, and HM Dice scores for (a) points and scribbles, and (b) boxes and partial masks. Partial mask context remains close to full mask performance even on unseen OOD datasets.
Without a segmentation decoder, MedIC runs at 0.172 s/image (5.82 FPS) on a single NVIDIA A100 (40GB), approximately 2.5×, 4.0×, and 12.7× faster than INSID3, GF-SAM†, and Matcher†, respectively.
| Method | FLOPs (G) | Time (s) | FPS |
|---|---|---|---|
| GF-SAM† | 7,743.5 | 0.690 | 1.45 |
| Matcher† | 7,867.2 | 2.185 | 0.46 |
| INSID3 | 5,068.6 | 0.429 | 2.33 |
| MedIC (Ours) | 1,402.4 | 0.172 | 5.82 |
Visual comparison against Matcher† and INSID3 across Points, Boxes, Scribbles, Partial Mask, Full Mask, and ID → OOD domain generalization. MedIC adheres closely to anatomical boundaries with substantially reduced spillover into surrounding tissue under both sparse reference annotations and domain shifts.
Qualitative comparison with Matcher† and INSID3 under different reference annotations and domain generalization. Blue denotes target ground truth and orange denotes predictions.
Domain generalization ablation with one fully annotated ID reference. Removing foreground–background contrast produces the largest harmonic-mean drop (83.67% to 54.52%), highlighting its role in suppressing ambiguous background affinities.
| Method | Domain Generalization | ||
|---|---|---|---|
| ID DSC (%) | OOD DSC (%) | HM DSC (%) | |
| MedIC (Ours) | 85.49 | 81.93 | 83.67 |
| Component Removal | |||
| w/o Multiple Reference Prototypes | 82.31(−3.18)↓ | 81.78(−0.15)↓ | 82.05(−1.62)↓ |
| w/o Foreground–Background Contrast | 55.52(−29.97)↓ | 53.56(−28.37)↓ | 54.52(−29.15)↓ |
| w/o Graph-Based Feature Aggregation | 84.36(−1.13)↓ | 80.77(−1.16)↓ | 82.53(−1.14)↓ |
| w/o Adaptive Label Selection | 82.18(−3.31)↓ | 76.92(−5.01)↓ | 79.45(−4.22)↓ |
| w/o Multiple Reference Prototypes & Graph Aggregation | 81.13(−4.36)↓ | 80.99(−0.94)↓ | 81.06(−2.61)↓ |
| Graph-Based Feature Aggregation Alternatives | |||
| → Local Spatial Diffusion | 84.42(−1.07)↓ | 80.87(−1.06)↓ | 82.60(−1.07)↓ |
| → Hard Label Clustering | 83.91(−1.58)↓ | 79.41(−2.52)↓ | 81.60(−2.07)↓ |
| Foreground–Background Contrast Alternatives | |||
| → kNN Reference Matching | 83.76(−1.73)↓ | 80.60(−1.33)↓ | 82.15(−1.52)↓ |
| → Adaptive von Mises–Fisher Modeling | 81.69(−3.80)↓ | 79.21(−2.72)↓ | 80.43(−3.24)↓ |
| → Optimal Transport Matching | 83.66(−1.83)↓ | 79.82(−2.11)↓ | 81.70(−1.97)↓ |
Reference annotation budget. Mean DSC across 11 ID datasets. Retaining even 10% of foreground patches yields 80.32% DSC (vs. 80.97% for full masks).
| Kmax | ID DSC (%) | OOD DSC (%) | HM DSC (%) | Runtime (ms/img) |
|---|---|---|---|---|
| 1 | 82.31 | 81.78 | 82.05 | 159.0 |
| 2 | 84.33 | 81.43 | 82.86 | 168.9 |
| 4 | 85.49 | 81.93 | 83.67 | 171.8 |
| 8 | 85.28 | 81.77 | 83.49 | 201.2 |
| 16 | 85.27 | 82.13 | 83.67 | 219.8 |
| Model | Backbone | ID DSC (%) | OOD DSC (%) | HM DSC (%) |
|---|---|---|---|---|
| DINOv2 | ViT-S/14 | 73.69 | 69.17 | 71.36 |
| DINOv2 | ViT-B/14 | 75.27 | 69.99 | 72.53 |
| DINOv2 | ViT-L/14 | 74.56 | 70.09 | 72.25 |
| DINOv3 | ViT-S/16 | 80.68 | 76.58 | 78.57 |
| DINOv3 | ViT-B/16 | 80.00 | 74.94 | 77.38 |
| DINOv3 | ViT-L/16 | 85.49 | 81.93 | 83.67 |
@article{koleilat2026medic,
title = {MedIC: Efficient and Generalizable Training-free In-Context Medical Image Segmentation},
author = {Koleilat, Taha and Asgariandehkordi, Hojat and Nejati Manzari, Omid and Abdelwahed, Omar and Rivaz, Hassan and Xiao, Yiming},
year = {2026}
}