Preprint
Article

This version is not peer-reviewed.

A Prompt-Preserving MedSAM Enhancement Framework with Historical Feature Fusion and Soft Convolutional Expert Weighting for Medical Image Segmentation

Submitted:

30 June 2026

Posted:

01 July 2026

You are already at the latest version

Abstract
Accurate medical image segmentation is a core task in biomedical engineering and computer-assisted image analysis. Prompt-based segmentation models, such as Med-SAM, allow anatomical structures or lesions to be delineated from sparse user inputs, but two-dimensional clinical images often contain small targets, weak boundaries, heterogeneous lesion textures, and modality-specific noise. These factors can reduce the reliability of prompt-conditioned masks when early structural cues are weakened during deep encoder propagation. We propose HBF-BCER MedSAM, a prompt-preserving enhancement framework that primarily strengthens MedSAM image-encoder representations while retaining the original point- and box-prompt interface. Historical Branch Fusion (HBF) reinjects cross-layer structural summaries from previous enhanced blocks, whereas Balanced Convolutional Expert Routing (BCER) performs soft pixel-wise weighting of heterogeneous convolutional experts in bottleneck space under a load-balancing constraint. Experiments on REFUGE2, ISIC2016, and TNMIX under matched simulated-prompt protocols show consistent improvements over the matched MedSAM baseline. Dice/IoU increased from 82.1%/73.8% to 91.0%/83.7% for REFUGE2 optic cup segmentation, from 87.5%/78.6% to 95.9%/92.4% on ISIC2016, and from 81.6%/75.1% to 91.4%/85.1% on TNMIX. Qualitative comparisons, convergence analysis, and ablation studies further support the effectiveness of preserving historical structural evidence and applying adaptive local expert weighting for prompt-conditioned medical image segmentation.
Keywords: 
;  ;  ;  ;  ;  ;  

1. Introduction

Medical image segmentation is an important component of biomedical engineering systems for image-guided diagnosis, treatment planning, and quantitative image analysis. Deep segmentation networks have achieved strong performance in many medical imaging tasks, but fully automatic segmentation can be sensitive to target ambiguity, weak boundaries, and domain-specific appearance shifts. Prompt-based segmentation provides a practical alternative by allowing a sparse user input, such as a point or a box, to specify the intended anatomical structure or lesion. The Segment Anything Model (SAM) introduced a general image-encoder, prompt-encoder, and mask-decoder pipeline for segmenting user-specified targets from sparse prompts [1]. MedSAM adapted this promptable interface to medical images through large-scale medical-domain training and has become a representative baseline for SAM-style medical image segmentation [2].
Despite this progress, prompt-based medical image segmentation remains difficult in common two-dimensional imaging scenarios. Fundus images contain nested optic disc and cup structures, which makes accurate cup/disc delineation sensitive to small structural errors [3,4]. Dermoscopic lesion segmentation is challenging because lesion borders are often fuzzy, irregular, and visually heterogeneous [5,6]. Thyroid ultrasound segmentation further suffers from low contrast, speckle noise, and ambiguous nodule margins, which are well-recognized issues in ultrasound segmentation studies [7,8]. Recent attention-based thyroid nodule methods also confirm the importance of region priors and boundary-aware representation [9]. In such settings, the mask decoder must rely on image tokens that preserve small structures, weak edges, and heterogeneous local appearances while still responding to the prompt.
Existing medical adaptations of SAM mainly improve domain adaptation, prompt-conditioned evaluation, or decoder-side adaptation around the original promptable pipeline [2,10,11]. Empirical evaluations have also shown that SAM-style models can behave unevenly across modalities, target types, and prompt settings [12,13]. These findings motivate a complementary encoder-side question: how can promptable medical segmentation retain early structural evidence and adapt local feature enhancement before prompt-conditioned decoding? This question is particularly relevant for biomedical image analysis, where local boundary evidence and small-target structures may be clinically meaningful even when the final task is formulated as a binary mask prediction.
To address this problem, we propose HBF-BCER, a prompt-preserving framework that primarily strengthens MedSAM image-encoder representations. As shown in Figure 1, the framework keeps the original point- and box-prompt interface unchanged, uses the same lightweight decoder-adapter setting across adapted variants, and enhances selected image-encoder blocks with two modules. Historical Branch Fusion (HBF) reinjects cross-layer bottleneck summaries from previous enhanced blocks, making boundary- and small-target-related evidence more accessible to deeper blocks. Balanced Convolutional Expert Routing (BCER) performs soft pixel-wise weighting among heterogeneous convolutional experts, allowing local enhancement to adapt to regions with different textures and boundary conditions. The framework is evaluated on REFUGE2, ISIC2016, and TNMIX under matched simulated-prompt protocols. HBF-BCER improves the matched MedSAM baseline on all three datasets, with REFUGE2 optic cup Dice/IoU increasing from 82.1/73.8 to 91.0/83.7, ISIC2016 Dice/IoU from 87.5/78.6 to 95.9/92.4, and TNMIX Dice/IoU from 81.6/75.1 to 91.4/85.1.
The main contributions of this work are summarized as follows:
  • We propose a prompt-preserving MedSAM enhancement framework that keeps the original point- and box-prompt interface unchanged and primarily targets image-encoder representations.
  • We design HBF to reuse historical bottleneck features from previous enhanced blocks, improving the preservation of boundary and small-target cues during deep token propagation.
  • We design BCER as a soft pixel-wise convolutional expert-weighting module, enabling adaptive local enhancement for heterogeneous medical image regions while avoiding claims of sparse top-k MoE routing.
  • We provide matched prompt-based comparisons and ablation analyses on fundus, dermoscopic, and thyroid ultrasound datasets, demonstrating consistent improvements over the matched MedSAM baseline under identical simulated-prompt settings.

3. Materials and Methods

3.1. Overall Framework

Figure 1 shows the proposed HBF-BCER framework. Given an input image I R B × 3 × H × W and a prompt set P, the model follows the standard promptable segmentation pipeline. The normalized image I ˜ is transformed into patch tokens and combined with the pretrained image-encoder positional embedding:
X ( 0 ) = ϕ patch ( I ˜ ) + I ( E pos enc , pre ) ,
where I ( · ) denotes positional-embedding interpolation and reduces to an identity mapping when the input size matches the pretrained configuration. Standard MedSAM encoder layers are denoted by T l ( · ) . For layers that are not selected for enhancement, the token update is
X ( l + 1 ) = T l ( X ( l ) ) .
For the selected enhanced layers L enh = { 3 , 6 , 9 , 12 } under one-based indexing, the standard transformer output is first computed and then refined by HBF and BCER:
Y t = T l t ( X ( l t ) ) , l t L enh ,
X ¯ t = Y t + B hbf ( l t ) + B hist ( l t ) ,
X ( l t + 1 ) = X ¯ t + B exp ( l t ) .
Here B hbf ( l t ) , B hist ( l t ) , and B exp ( l t ) are the current HBF response, historical bias, and BCER expert bias, respectively. This sequence is consistent with the architectural path in Figure 1: transformer block, HBF, and BCER. The final image tokens are projected as F img = ϕ proj ( X ( L ) ) . The prompt encoder produces sparse and dense prompt embeddings, and the mask decoder predicts low-resolution masks that are subsequently upsampled to the target resolution.
The design is prompt preserving rather than prompt redesigning. The point- and box-prompt interface remains unchanged, and the proposed HBF and BCER modules operate on the image-encoder representation. A lightweight decoder adapter is used as a controlled adaptation component and is kept consistent across adapted variants. Therefore, the main controlled comparison isolates the effect of image-encoder enhancement from prompt-coordinate variation and from changes in the prompt interface.

3.2. Lightweight Decoder Adapter and Adaptation Scope

The proposed novelty lies in HBF and BCER, which are inserted into selected image-encoder blocks. In the implemented adaptation setting, the pretrained ViT-B image encoder is frozen except for the added HBF and BCER parameters. The original prompt encoder and the user-facing point/box prompt interface are preserved. A lightweight decoder adapter is trained to provide a controlled amount of task-specific mask-decoding capacity, but this adapter is not treated as an independent contribution. It is kept identical in all adapted variants used for ablation, including the HBF-only, BCER-only, and full HBF-BCER settings. This clarification distinguishes four settings that should not be conflated: the original MedSAM model, a fully fine-tuned MedSAM reference, a frozen MedSAM model with a lightweight decoder adapter, and the proposed HBF-BCER variant.

3.3. Historical Branch Fusion

Let the t-th enhanced block correspond to encoder layer l t L enh . The standard transformer output Y t R B × N × C is first compressed by a bottleneck projection:
D t = ϕ bn ( Y t ) , D t R B × N b × C b ,
where C b = C / 4 . No spatial downsampling is used in the reported setting; therefore, N b = N and H b = W b = 64 for a 1024 × 1024 input with patch size 16. The historical memory stores bottleneck representations from previous enhanced blocks:
M t = { D max ( 1 , t K ) , , D t 1 } , K t = min ( K , t 1 ) ,
where K = 3 . When K t = 0 , the historical bias is set to zero. Otherwise, the historical summary is computed as
H sum , t = 1 K t j = max ( 1 , t K ) t 1 ϕ align ( D j ) ,
where ϕ align is an identity mapping in the single-scale experiments. The summary is then projected back to the main token dimension:
B hist ( l t ) = ψ up ( H sum , t ) .
Inside the current enhanced block, M lightweight branch transforms operate on D t :
R t , m = τ m ( D t ) , m = 1 , , M .
A learnable non-negative matrix W t R M × M is normalized by Sinkhorn iterations to obtain a doubly stochastic mixing matrix [33]:
S t = Sinkhorn ( W t ) , q = 1 M S t , m q = 1 , m = 1 M S t , m q = 1 .
The mixed response of branch m is
R ¯ t , m = q = 1 M S t , m q R t , q .
To avoid reducing the doubly stochastic mixing to a uniform average, the final HBF response uses learnable branch-aggregation weights:
α t = Softmax ( a t ) , R mix , t = m = 1 M α t , m R ¯ t , m ,
where a t R M is learned for the t-th enhanced block. This formulation preserves the effect of the Sinkhorn-normalized branch-mixing matrix while allowing the model to emphasize informative mixed branches. The current HBF response is
B hbf ( l t ) = ψ mix ( R mix , t ) .
Thus, HBF provides two complementary terms: a current branch-mixed response B hbf ( l t ) and a cross-layer historical bias B hist ( l t ) . Figure 2 illustrates the HBF module.

3.4. Balanced Convolutional Expert Routing

BCER enhances local image patterns after HBF refinement. For the t-th enhanced block, the HBF-refined tokens X ¯ t are projected to the bottleneck space and folded into a spatial feature map:
Z t = ϕ fold ( ϕ bn ( X ¯ t ) ) R B × C b × H b × W b .
The default implementation uses three convolutional experts: 3 × 3 and 5 × 5 depthwise–pointwise experts, and a 1 × 1 expert with GELU activation. Their outputs are
U t , e = f t , e ( Z t ) , e = 1 , , E .
A lightweight router predicts spatial expert logits G t = g t ( Z t ) . The soft pixel-wise expert weights are
A t = Softmax ( G t / τ r , t ) , A t R B × E × H b × W b ,
where the softmax is applied over the expert dimension and τ r , t is the routing temperature. This operation softly combines all experts at each spatial position rather than selecting a sparse top-1 or top-k expert. The routed representation and expert bias are computed as
Z t = e = 1 E A t , e U t , e , B exp ( l t ) = ψ proj ( l t ) ( ϕ unfold ( Z t ) ) .
The final enhanced-block output is obtained by adding the expert bias to the HBF-refined tokens:
X ( l t + 1 ) = X ¯ t + B exp ( l t ) .
To prevent a small number of experts from dominating the routing distribution, a load-balancing term is applied. The mean activation of expert e in the t-th enhanced block is
μ t , e = 1 B H b W b b = 1 B u = 1 H b v = 1 W b A t , b , e , u , v ,
and the balancing loss is
L bal , t = 1 E e = 1 E μ t , e 1 E 2 .
Figure 3 shows the BCER module.

3.5. Optimization Objective

HBF-BCER is trained with a segmentation loss and the routing-balancing loss. The segmentation loss combines Dice loss and binary cross-entropy, which is commonly used for class-imbalanced medical segmentation [34,35]. Let M ^ denote the predicted mask and M the ground-truth mask. For channel c = 1 , , C m ,
L seg = c = 1 C m ω c L Dice ( M ^ c , M c ) + L BCE ( M ^ c , M c ) .
The total objective is
L total = L seg + λ bal t = 1 T L bal , t ,
where T = | L enh | and λ bal = 0.01 .

4. Experiments and Results

4.1. Datasets and Implementation Details

We evaluate HBF-BCER on three two-dimensional medical image segmentation datasets. REFUGE2 is used for optic disc/cup segmentation and follows a fixed 800/400 train/validation split [3,4]. ISIC2016 is used for dermoscopic skin lesion segmentation and follows the official train/test protocol [5,6]. TNMIX is used for thyroid ultrasound nodule segmentation and reflects common ultrasound challenges, including low contrast, speckle noise, and ambiguous nodule margins [7,8,9]. In this work, TNMIX follows a fixed processed benchmark protocol with 3600 images for training and 370 images for evaluation after preprocessing and quality filtering. This setting provides a consistent thyroid-ultrasound test bed for paired comparison between MedSAM and HBF-BCER under identical prompts, preprocessing, and metric computation.
The base promptable model is MedSAM with a SAM ViT-B image encoder and the standard image encoder–prompt encoder–mask decoder pipeline [2]. Unless otherwise stated, HBF-BCER freezes the pretrained image encoder and trains the added HBF and BCER parameters together with the lightweight decoder adapter. The matched MedSAM baseline uses the same prompt protocol, preprocessing, optimizer, and metric pipeline. To avoid ambiguity, “matched MedSAM baseline” in this paper denotes the MedSAM reference under the same simulated prompt and training/evaluation pipeline, whereas “fully fine-tuned MedSAM” is used only for trainable-parameter efficiency framing. We use Adam with an initial learning rate of 1 × 10 4 , zero weight decay, batch size 2, and a StepLR scheduler with step size 10 and γ = 0.5 . Training lasts 40 epochs for REFUGE2, 20 epochs for ISIC2016, and 40 epochs for TNMIX on a single NVIDIA RTX 3090 GPU. The enhanced block set is L enh = { 3 , 6 , 9 , 12 } , the memory length is K = 3 , the branch number is M = 2 , the number of experts is E = 3 , and the routing temperature is initialized to 1 and clipped to [0.1, 10].
Table 1. Definition of MedSAM-related settings used or discussed in this paper. This table separates matched accuracy baselines, ablation controls, and efficiency references.
Table 1. Definition of MedSAM-related settings used or discussed in this paper. This table separates matched accuracy baselines, ablation controls, and efficiency references.
Setting Image Encoder Prompt Encoder Mask Decoder Decoder Adapter HBF BCER Main Purpose
Original MedSAM Pretrained Pretrained Original No No No Reference model definition
Fully fine-tuned MedSAM Trainable Task dependent Trainable No No No Trainable-parameter efficiency reference
Frozen MedSAM + Adapter Frozen Frozen Adapter-enhanced Yes No No Adapter-control concept
HBF-only variant Frozen Frozen Adapter-enhanced Yes Yes No Ablation control
BCER-only variant Frozen Frozen Adapter-enhanced Yes No Yes Ablation control
HBF-BCER Frozen Frozen Adapter-enhanced Yes Yes Yes Proposed framework

4.2. Prompt Protocol and Metrics

For REFUGE2, disc and cup are predicted as two binary output channels. During training, six positive points are sampled for each image, with three from the disc foreground and three from the cup foreground. A box prompt is enabled with probability 2 / 3 , and its target overlap is sampled from { 0.5 ,   0.75 } . During inference, the main comparison uses a fixed simulated point-prompt protocol without iterative correction. For ISIC2016 and TNMIX, both training and inference use single-target positive point prompts. MedSAM and HBF-BCER receive identical prompt coordinates for paired comparison. This fixed protocol is suitable for isolating representation differences, but it does not fully model real clinical prompt variation; this limitation is discussed explicitly in Section 5.
Dice and Intersection over Union (IoU) are used as the primary overlap metrics [36,37]. REFUGE2 reports disc and cup metrics separately, whereas ISIC2016 and TNMIX report single-target metrics. HD95 is used as a complementary boundary-distance metric and is reported in pixels under the adopted mask resolution [38,39]. Because overlap and boundary-distance metrics capture different error modes, HD95 is interpreted together with Dice/IoU rather than as a redundant measurement [34].

4.3. Matched Prompt-Based Results

Table 2 summarizes the completed matched prompt-based comparison. Under identical simulated prompt inputs, HBF-BCER improves MedSAM on all three datasets. For REFUGE2 optic cup segmentation, Dice/IoU increase from 82.1/73.8 to 91.0/83.7. On ISIC2016, Dice/IoU improve from 87.5/78.6 to 95.9/92.4. On TNMIX, Dice/IoU improve from 81.6/75.1 to 91.4/85.1. These gains are interpreted within each dataset protocol rather than as a single cross-dataset ranking.

4.4. Literature-Reported SAM-Style Reference Results

Recent SAM-style medical segmentation methods are rapidly evolving. To position HBF-BCER with respect to this literature without mixing incompatible protocols, Table 3 summarizes public literature-reported results from Medical SAM 2 on related 2D medical image segmentation benchmarks [15]. These values are not treated as a matched comparison with HBF-BCER because the source paper used its own training, prompt, preprocessing, split, and metric protocols. In particular, the ISIC column in the source corresponds to ISIC 2019 rather than the ISIC2016 protocol used in our main experiments. The same source describes TNMIX as a thyroid-ultrasound benchmark combining 4554 images from TNSCUI and 637 images from DDTI; the 3600/370 setting adopted here is used as a fixed processed split for the controlled MedSAM versus HBF-BCER comparison.

4.5. Non-Prompted Structural References

Table 4 provides structural context using non-prompted segmentation references. These methods do not use prompt inputs and are therefore not matched prompt-based competitors. They are reported only to show how the adopted protocol relates to conventional automatic segmentation architectures. The author-implemented “style” variants denote two-dimensional implementations inspired by the corresponding architectures rather than official challenge submissions. Metrics are computed by the same per-image averaging protocol used in Table 2; therefore, Dice and IoU values should be interpreted as separately averaged metrics rather than converted from a single global confusion matrix.

4.6. Ablation Study

Table 5 evaluates the contributions of HBF and BCER. The row without HBF and without BCER corresponds to the matched MedSAM reference under the same simulated-prompt setting. For the HBF-only, BCER-only, and full variants, the decoder-adapter setting and training protocol are kept unchanged. Therefore, the differences among these rows reflect the encoder-side module switches rather than changes in the decoder configuration.
The single-module variants improve Dice/IoU over the matched reference, while the full HBF-BCER model achieves the best Dice/IoU on all three datasets. REFUGE2 disc HD95 decreases from 35.9 to 6.5. ISIC2016 HD95 worsens for the single-module variants but improves when HBF and BCER are used jointly, indicating that overlap and boundary-distance metrics capture complementary behavior. This pattern supports the design choice of coupling historical structural fusion with adaptive local expert weighting.

4.7. Qualitative, Convergence, and Efficiency Analysis

The qualitative cases in Figure 4, Figure 5, Figure 6 and Figure 7 are consistent with the quantitative improvements. On REFUGE2, HBF-BCER preserves the small optic cup region more consistently under the fixed prompt protocol. On ISIC2016, it produces more complete lesion masks with reduced local leakage near fuzzy boundaries. On TNMIX, it maintains more contiguous nodule regions under low contrast and speckle noise. These visual observations support, but do not by themselves prove, the mechanisms suggested by the ablation results.
Figure 8 reports REFUGE2 convergence behavior. The training loss decreases rapidly in the early epochs, and validation Dice reaches a stable plateau under the adopted training setting. The method also changes the accuracy–efficiency trade-off. With a SAM ViT-B backbone and a 1024 × 1024 input, fully trainable MedSAM contains 93.74M trainable parameters, 93.74M total parameters, 976.91G FLOPs, and 125.71 ms inference time per image. HBF-BCER contains 17.30M trainable parameters and 111.03M total parameters, with 1039.36G FLOPs and 144.62 ms per image. Thus, it reduces trainable parameters by 81.5%, while increasing total parameters, FLOPs, and inference time by 18.4%, 6.4%, and 15.0%, respectively. This means that the reduction is due to freezing most pretrained parameters rather than to a smaller overall model.

5. Discussion

From a biomedical engineering perspective, the results indicate that preserving structural evidence inside a promptable foundation-model pipeline can improve the reliability of interactive segmentation across several medical imaging modalities. The results support the complementarity of HBF and BCER. HBF is most relevant when early structural cues must be preserved, which is consistent with the large improvement for REFUGE2 optic cup segmentation. BCER is useful when local appearance varies across the image, as in dermoscopic lesions and thyroid ultrasound nodules. The ablation results further show that overlap accuracy and boundary-distance behavior do not always change in the same direction; therefore, HBF-BCER should be interpreted as improving the overall prompt-conditioned segmentation behavior in the evaluated settings rather than as uniformly optimizing every boundary metric in every partial variant.
The comparison with recent SAM-style methods should be interpreted carefully. The public results in Table 3 show that strong medical SAM adaptations such as SAM-Med2D, Medical SAM Adapter, and Medical SAM 2 have become important reference points [10,11,15]. However, those values use different source protocols and are not a substitute for a fully matched rerun. For this reason, our main controlled claim remains the paired improvement over the matched MedSAM baseline under identical prompts and splits. This conservative framing avoids conflating public literature results with author-run matched experiments.
The efficiency profile is also explicit. HBF-BCER reduces trainable parameters relative to full MedSAM fine-tuning, but it increases total parameters, FLOPs, and inference time because the encoder contains additional historical-fusion and soft expert-weighting modules. This trade-off is acceptable for offline and near-interactive segmentation settings, but it should be optimized before deployment in latency-sensitive workflows such as real-time ultrasound.
Several limitations remain. First, the present study focuses on two-dimensional prompt-based segmentation with simulated point and box prompts. Real interactive clinical prompts may be noisier and should be evaluated with repeated prompt sampling, point shifts, box perturbations, and iterative correction. Second, the current evidence is based on three representative two-dimensional datasets; broader validation on additional external datasets and acquisition environments would further clarify generalization. Third, the ViT-B experiments do not fully determine how HBF and BCER scale to larger SAM backbones or SAM2-based architectures. Finally, the current study does not include a full matched rerun of all recent PEFT baselines under the same protocol. These limitations do not invalidate the paired MedSAM comparison, but they define the scope in which the conclusions should be interpreted.

6. Conclusions

Accurate prompt-based medical image segmentation is important for interactive image analysis because clinical targets are often small, weakly contrasted, and dependent on explicit user intent. This study introduced HBF-BCER, a prompt-preserving framework that primarily strengthens MedSAM image-encoder representations while keeping the standard point- and box-prompt interface unchanged. The framework combines Historical Branch Fusion, which reinjects cross-layer structural summaries to preserve boundary- and small-target-related evidence, with Balanced Convolutional Expert Routing, which performs soft pixel-wise weighting among bottleneck convolutional experts to adapt local enhancement to heterogeneous medical appearances. Under matched simulated-prompt protocols, HBF-BCER improved the matched MedSAM baseline on REFUGE2, ISIC2016, and TNMIX: REFUGE2 optic cup Dice/IoU increased from 82.1/73.8 to 91.0/83.7, ISIC2016 Dice/IoU increased from 87.5/78.6 to 95.9/92.4, and TNMIX Dice/IoU increased from 81.6/75.1 to 91.4/85.1. These results suggest that encoder-side historical evidence preservation and adaptive local expert weighting can improve prompt-conditioned segmentation of nested optic structures, irregular dermoscopic lesions, and low-contrast thyroid ultrasound nodules in the evaluated settings. In addition, HBF-BCER reduces the number of trainable parameters relative to full MedSAM fine-tuning, although it introduces additional total parameters, FLOPs, and inference latency. Overall, the proposed framework provides a practical route for improving SAM-style medical segmentation while retaining prompt compatibility; further validation with realistic interactive prompts, matched PEFT baselines, larger multi-center datasets, and three-dimensional imaging scenarios is necessary to clarify its broader clinical generalizability.

Author Contributions

Conceptualization, S.P. and Z.L.; methodology, S.P. and Z.L.; software, S.P., L.L., B.W. and T.W.; validation, S.P. and L.Y.; formal analysis, S.P.; investigation, S.P. and L.L.; resources, Z.L., L.Z. and L.Y.; data curation, S.P. and L.Y.; writing—original draft preparation, S.P.; writing—review and editing, Z.L., L.Z. and L.Y.; visualization, S.P.; supervision, Z.L. and L.Z.; project administration, Z.L. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable. This study used publicly available de-identified medical image segmentation datasets and did not involve newly collected human-subject data.

Data Availability Statement

REFUGE2 and ISIC2016 are publicly available from their respective challenge or dataset repositories. The TNMIX benchmark follows the public thyroid ultrasound benchmark setting described in the cited literature. Additional implementation details are available from the corresponding author upon reasonable request.

Acknowledgments

The authors thank the maintainers of the public medical image datasets used in this study. No AI tool was used to generate experimental data, alter scientific images, or draw scientific conclusions. The authors reviewed and edited all AI-assisted text and take full responsibility for the content of the article.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
SAM Segment Anything Model
MedSAM Medical Segment Anything Model
HBF Historical Branch Fusion
BCER Balanced Convolutional Expert Routing
PEFT Parameter-efficient fine-tuning
IoU Intersection over Union
HD95 95th percentile Hausdorff distance

References

  1. Kirillov, A.; Mintun, E.; Ravi, N.; Mao, H.; Rolland, C.; Gustafson, L.; Xiao, T.; Whitehead, S.; Berg, A.C.; Lo, W.Y.; et al. Segment Anything. In Proceedings of the Proceedings of the IEEE/CVF International Conference on Computer Vision, 2023; pp. 4015–4026. [Google Scholar]
  2. Ma, J.; He, Y.; Li, F.; Han, L.; You, C.; Wang, B. Segment Anything in Medical Images. Nat. Commun. 2024, 15, 654. [Google Scholar] [CrossRef] [PubMed]
  3. Orlando, J.I.; Fu, H.; Breda, J.B.; van Keer, K.; Bathula, D.R.; Diaz-Pinto, A.; Fang, R.; Heng, P.A.; Kim, J.; Lee, J.; et al. REFUGE Challenge: A Unified Framework for Evaluating Automated Methods for Glaucoma Assessment from Fundus Photographs. Med. Image Anal. 2020, 59, 101570. [Google Scholar] [CrossRef] [PubMed]
  4. Bazi, Y.; Rahhal, M.M.A.; Elgibreen, H.; Zuair, M. Vision Transformers for Segmentation of Disc and Cup in Retinal Fundus Images. Biomed. Signal Process. Control 2024, 91, 105915. [Google Scholar] [CrossRef]
  5. Cassidy, B.; Kendrick, C.; Brodzicki, A.; Jaworek-Korjakowska, J.; Yap, M.H. Analysis of the ISIC Image Datasets: Usage, Benchmarks and Recommendations. Med. Image Anal. 2022, 75, 102305. [Google Scholar] [CrossRef] [PubMed]
  6. Mirikharaji, Z.; Abhishek, K.; Bissoto, A.; Barata, C.; Avila, S.; Valle, E.; Celebi, M.E.; Hamarneh, G. A Survey on Deep Learning for Skin Lesion Segmentation. Med. Image Anal. 2023, 88, 102863. [Google Scholar] [CrossRef] [PubMed]
  7. Chen, J.; You, H.; Li, K. A Review of Thyroid Gland Segmentation and Thyroid Nodule Segmentation Methods for Medical Ultrasound Images. Comput. Methods Programs Biomed. 2020, 185, 105329. [Google Scholar] [CrossRef] [PubMed]
  8. Kang, Q.; Lao, Q.; Li, Y.; Jiang, Z.; Qiu, Y.; Zhang, S.; Li, K. Thyroid Nodule Segmentation and Classification in Ultrasound Images Through Intra- and Inter-Task Consistent Learning. Med. Image Anal. 2022, 79, 102443. [Google Scholar] [CrossRef] [PubMed]
  9. Gong, H.; Chen, J.; Chen, G.; Li, H.; Li, G.; Chen, F. Thyroid Region Prior Guided Attention for Ultrasound Segmentation of Thyroid Nodules. Comput. Biol. Med. 2023, 155, 106389. [Google Scholar] [CrossRef] [PubMed]
  10. Cheng, J.; Ye, J.; Deng, Z.; Chen, J.; Li, T.; Wang, H.; Su, Y.; Huang, Z.; Chen, J.; Jiang, L.; et al. SAM-Med2D. arXiv 2023, arXiv:2308.16184. [Google Scholar]
  11. Wu, J.; Ji, W.; Liu, Y.; Fu, H.; Xu, M.; Xu, Y.; Jin, Y. Medical SAM Adapter: Adapting Segment Anything Model for Medical Image Segmentation. arXiv 2023, arXiv:2304.12620. [Google Scholar]
  12. Mazurowski, M.A.; Dong, H.; Gu, H.; Yang, J.; Konz, N.; Zhang, Y. Segment Anything Model for Medical Image Analysis: An Experimental Study. Med. Image Anal. 2023, 89, 102918. [Google Scholar] [CrossRef] [PubMed]
  13. Huang, Y.; Yang, X.; Liu, L.; Zhou, H.; Chang, A.; Zhou, X.; Chen, R.; Yu, J.; Chen, J.; Chen, C. Segment Anything Model for Medical Images? Med. Image Anal. 2024, 92, 103061. [Google Scholar] [CrossRef] [PubMed]
  14. Xiong, X.; Wu, Z.; Tan, S.; Li, W.; Tang, F.; Chen, Y.; Li, S.; Ma, J.; Li, G. SAM2-UNet: Segment Anything 2 Makes Strong Encoder for Natural and Medical Image Segmentation. Vis. Intell. 2026. [Google Scholar] [CrossRef]
  15. Zhu, J.; Hamdi, A.; Qi, Y.; Jin, Y.; Wu, J. Medical SAM 2: Segment Medical Images as Video via Segment Anything Model 2. arXiv 2024, arXiv:2408.00874. [Google Scholar]
  16. Ma, J.; Yang, Z.; Kim, S.; Chen, B.; Baharoon, M.; Fallahpour, A.; Asakereh, R.; Lyu, H.; Wang, B. MedSAM2: Segment Anything in 3D Medical Images and Videos. arXiv 2025, arXiv:2504.03600. [Google Scholar]
  17. Zhou, L.; Hu, J.; Zhang, S.; Du, X.; Song, M.; Zhang, X.; Feng, Z. DenseSAM: Semantic Enhance SAM for Efficient Dense Object Segmentation. Proceedings of the Proceedings of the Thirty-Fourth International Joint Conference on Artificial Intelligence, IJCAI-25. International Joint Conferences on Artificial Intelligence Organization 2025, 7994–8002. [Google Scholar] [CrossRef] [PubMed]
  18. Ronneberger, O.; Fischer, P.; Brox, T. U-Net: Convolutional Networks for Biomedical Image Segmentation. In Proceedings of the Medical Image Computing and Computer-Assisted Intervention – MICCAI 2015; Springer, 2015; pp. 234–241. [Google Scholar] [CrossRef]
  19. Zhou, Z.; Siddiquee, M.M.R.; Tajbakhsh, N.; Liang, J. UNet++: Redesigning Skip Connections to Exploit Multiscale Features in Image Segmentation. IEEE Trans. Med. Imaging 2020, 39, 1856–1867. [Google Scholar] [CrossRef] [PubMed]
  20. Isensee, F.; Jaeger, P.F.; Kohl, S.A.A.; Petersen, J.; Maier-Hein, K.H. nnU-Net: A Self-Configuring Method for Deep Learning-Based Biomedical Image Segmentation. Nat. Methods 2021, 18, 203–211. [Google Scholar] [CrossRef] [PubMed]
  21. Chen, J.; Mei, J.; Li, X.; Lu, Y.; Yu, Q.; Wei, Q.; Luo, X.; Xie, Y.; Adeli, E.; Wang, Y.; et al. TransUNet: Rethinking the U-Net Architecture Design for Medical Image Segmentation Through the Lens of Transformers. Med. Image Anal. 2024, 97, 103280. [Google Scholar] [CrossRef] [PubMed]
  22. Zou, Y.; Ge, Y.; Zhao, L.; Li, W. MR-Trans: MultiResolution Transformer for Medical Image Segmentation. Comput. Biol. Med. 2023, 165, 107456. [Google Scholar] [CrossRef] [PubMed]
  23. Liang, Z.; Zhao, K.; Liang, G.; Li, S.; Wu, Y.; Zhou, Y. MAXFormer: Enhanced Transformer for Medical Image Segmentation with Multi-Attention and Multi-Scale Features Fusion. Knowl.-Based Syst. 2023, 280, 110987. [Google Scholar] [CrossRef]
  24. Wu, H.; Min, W.; Gai, D.; Huang, Z.; Geng, Y.; Wang, Q.; Chen, R. HD-Former: A Hierarchical Dependency Transformer for Medical Image Segmentation. Comput. Biol. Med. 2024, 178, 108671. [Google Scholar] [CrossRef] [PubMed]
  25. Yang, R.; Liu, K.; Xu, S.; Yin, J.; Zhang, Z. ViT-UperNet: A Hybrid Vision Transformer with Unified-Perceptual-Parsing Network for Medical Image Segmentation. Complex Intell. Syst. 2024, 10, 3819–3831. [Google Scholar] [CrossRef]
  26. Ji, Z.; Chen, Z.; Ma, X. Grouped Multi-Scale Vision Transformer for Medical Image Segmentation. Sci. Rep. 2025, 15, 11122. [Google Scholar] [CrossRef] [PubMed]
  27. Fedus, W.; Zoph, B.; Shazeer, N. Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity. J. Mach. Learn. Res. 2022, 23, 1–39. [Google Scholar]
  28. Li, R.; Wu, L.; Gu, J.; Xu, Q.; Chen, W.; Cai, X.; Bu, J. MoE-SAM: Enhancing SAM for Medical Image Segmentation with Mixture-of-Experts. In Proceedings of the Medical Image Computing and Computer Assisted Intervention – MICCAI 2025; Springer, 2025; pp. 367–377. [Google Scholar] [CrossRef]
  29. Wei, J.; Zhao, X.; Woo, J.; Ouyang, J.; Fakhri, G.E.; Chen, Q.; Liu, X. Mixture-of-Shape-Experts (MoSE): End-to-End Shape Dictionary Framework to Prompt SAM for Generalizable Medical Segmentation. arXiv 2025, arXiv:2504.09601. [Google Scholar]
  30. Liu, J.; Desrosiers, C.; Zhou, Y. Att-MoE: Attention-Based Mixture of Experts for Nuclear and Cytoplasmic Segmentation. Neurocomputing 2020, 411, 139–148. [Google Scholar] [CrossRef]
  31. Zhang, Z.; Li, Y.; Shin, B.S. Learning Generalizable Visual Representation via Adaptive Spectral Random Convolution for Medical Image Segmentation. Comput. Biol. Med. 2023, 167, 107580. [Google Scholar] [CrossRef] [PubMed]
  32. Gao, J.; Zhou, S.; Yu, H.; Li, C.; Hu, X. SCESS-Net: Semantic Consistency Enhancement and Segment Selection Network for Audio–Visual Event Localization. Comput. Vis. Image Underst. 2025, 262, 104551. [Google Scholar] [CrossRef]
  33. Sinkhorn, R.; Knopp, P. Concerning Nonnegative Matrices and Doubly Stochastic Matrices. Pac. J. Math. 1967, 21, 343–348. [Google Scholar] [CrossRef]
  34. Kervadec, H.; Bouchtiba, J.; Desrosiers, C.; Granger, E.; Dolz, J.; Ayed, I.B. Boundary Loss for Highly Unbalanced Segmentation. Med. Image Anal. 2021, 67, 101851. [Google Scholar] [CrossRef] [PubMed]
  35. Ma, J.; Chen, J.; Ng, M.; Huang, R.; Li, Y.; Li, C.; Yang, X.; Martel, A.L. Loss Odyssey in Medical Image Segmentation. Med. Image Anal. 2021, 71, 102035. [Google Scholar] [CrossRef] [PubMed]
  36. Dice, L.R. Measures of the Amount of Ecologic Association Between Species. Ecology 1945, 26, 297–302. [Google Scholar] [CrossRef]
  37. Jaccard, P. The Distribution of the Flora in the Alpine Zone. New Phytol. 1912, 11, 37–50. [Google Scholar] [CrossRef]
  38. Huttenlocher, D.P.; Klanderman, G.A.; Rucklidge, W.J. Comparing Images Using the Hausdorff Distance. IEEE Trans. Pattern Anal. Mach. Intell. 1993, 15, 850–863. [Google Scholar] [CrossRef]
  39. Taha, A.A.; Hanbury, A. Metrics for Evaluating 3D Medical Image Segmentation: Analysis, Selection, and Tool. BMC Med. Imaging 2015, 15, 29. [Google Scholar] [CrossRef] [PubMed]
  40. Zhang, K.; Liu, X.; Shen, T.; Wu, J.; Dong, Y.; Zhang, R.; Huang, Z.; Wang, Q.; Zheng, Y.; Tian, J.; et al. Customize Segment Anything Model for Medical Image Segmentation. arXiv 2023, arXiv:2304.13785. [Google Scholar]
  41. Deng, G.; Zou, K.; Ren, K.; Wang, M.; Yang, X.; Xu, P.; Fu, H. SAM-U: Multi-Box Prompts Triggered Uncertainty Estimation for Reliable SAM in Medical Image. arXiv 2023, arXiv:2307.04973. [Google Scholar]
  42. Wu, H.; Chen, S.; Chen, G.; Wang, W.; Lei, B.; Wen, Z. FAT-Net: Feature Adaptive Transformers for Automated Skin Lesion Segmentation. Med. Image Anal. 2022, 76, 102327. [Google Scholar] [CrossRef] [PubMed]
  43. Alom, M.Z.; Yakopcic, C.; Hasan, M.; Taha, T.M.; Asari, V.K. Recurrent Residual U-Net for Medical Image Segmentation. J. Med. Imaging 2019, 6, 014006. [Google Scholar] [CrossRef] [PubMed]
  44. Hatamizadeh, A.; Nath, V.; Tang, Y.; Yang, D.; Roth, H.R.; Xu, D. Swin UNETR: Swin Transformers for Semantic Segmentation of Brain Tumors in MRI Images. In Proceedings of the Brainlesion: Glioma, Multiple Sclerosis, Stroke and Traumatic Brain Injuries; Springer, 2022; pp. 272–284. [Google Scholar] [CrossRef]
  45. Wang, W.; Chen, C.; Ding, M.; Yu, H.; Zha, S.; Li, J. TransBTS: Multimodal Brain Tumor Segmentation Using Transformer. In Proceedings of the Medical Image Computing and Computer Assisted Intervention – MICCAI 2021; Springer, 2021; pp. 109–119. [Google Scholar] [CrossRef] [PubMed]
Figure 1. Overall architecture of HBF-BCER. The framework retains the original MedSAM point- and box-prompt interface. Selected image-encoder blocks are enhanced by Historical Branch Fusion (HBF) and Balanced Convolutional Expert Routing (BCER), and the lightweight decoder-adapter setting is kept consistent across adapted variants.
Figure 1. Overall architecture of HBF-BCER. The framework retains the original MedSAM point- and box-prompt interface. Selected image-encoder blocks are enhanced by Historical Branch Fusion (HBF) and Balanced Convolutional Expert Routing (BCER), and the lightweight decoder-adapter setting is kept consistent across adapted variants.
Preprints 220942 g001
Figure 2. Historical Branch Fusion. HBF summarizes bottleneck features from previous enhanced blocks, injects the historical bias into the current enhanced block, and uses Sinkhorn-normalized branch mixing followed by learnable branch aggregation.
Figure 2. Historical Branch Fusion. HBF summarizes bottleneck features from previous enhanced blocks, injects the historical bias into the current enhanced block, and uses Sinkhorn-normalized branch mixing followed by learnable branch aggregation.
Preprints 220942 g002
Figure 3. Balanced Convolutional Expert Routing. BCER folds bottleneck tokens into a spatial feature map, predicts soft pixel-wise expert weights, fuses heterogeneous convolutional expert outputs, and projects the enhanced representation back to the token stream.
Figure 3. Balanced Convolutional Expert Routing. BCER folds bottleneck tokens into a spatial feature map, predicts soft pixel-wise expert weights, fuses heterogeneous convolutional expert outputs, and projects the enhanced representation back to the token stream.
Preprints 220942 g003
Figure 4. Qualitative comparison on REFUGE2 optic cup segmentation. The displayed masks focus on optic cup recovery under the same simulated prompt protocol.
Figure 4. Qualitative comparison on REFUGE2 optic cup segmentation. The displayed masks focus on optic cup recovery under the same simulated prompt protocol.
Preprints 220942 g004
Figure 5. Qualitative comparison on ISIC2016. The examples emphasize lesion contour completeness and reduced local leakage.
Figure 5. Qualitative comparison on ISIC2016. The examples emphasize lesion contour completeness and reduced local leakage.
Preprints 220942 g005
Figure 6. Qualitative comparison on TNMIX. The examples emphasize nodule-shape preservation under low contrast and speckle noise.
Figure 6. Qualitative comparison on TNMIX. The examples emphasize nodule-shape preservation under low contrast and speckle noise.
Preprints 220942 g006
Figure 7. Cross-dataset ablation visualization. The examples compare HBF-BCER with the matched MedSAM reference and single-module variants.
Figure 7. Cross-dataset ablation visualization. The examples compare HBF-BCER with the matched MedSAM reference and single-module variants.
Preprints 220942 g007
Figure 8. REFUGE2 convergence under the adopted training setting. Training loss decreases quickly in the early stage, while validation Dice reaches a stable plateau.
Figure 8. REFUGE2 convergence under the adopted training setting. Training loss decreases quickly in the early stage, while validation Dice reaches a stable plateau.
Preprints 220942 g008
Table 2. Completed matched prompt-based comparison on REFUGE2, ISIC2016, and TNMIX. MedSAM and HBF-BCER use identical simulated prompts, data splits, preprocessing, and metric computation. Values are percentages. Bold denotes the best result in the completed matched comparison.
Table 2. Completed matched prompt-based comparison on REFUGE2, ISIC2016, and TNMIX. MedSAM and HBF-BCER use identical simulated prompts, data splits, preprocessing, and metric computation. Values are percentages. Bold denotes the best result in the completed matched comparison.
Method REFUGE2 ISIC2016 TNMIX
Disc Dice Disc IoU Cup Dice Cup IoU Dice IoU Dice IoU
MedSAM [2] 93.8 86.2 82.1 73.8 87.5 78.6 81.6 75.1
HBF-BCER 95.4 91.3 91.0 83.7 95.9 92.4 91.4 85.1
Table 3. Public literature-reported SAM-style reference results from Medical SAM 2 [15]. Values are Dice/IoU percentages. These results are included only for contextual positioning because prompt protocols, splits, preprocessing, and the ISIC dataset version differ from our matched protocol.
Table 3. Public literature-reported SAM-style reference results from Medical SAM 2 [15]. Values are Dice/IoU percentages. These results are included only for contextual positioning because prompt protocols, splits, preprocessing, and the ISIC dataset version differ from our matched protocol.
Method REFUGE2 Disc REFUGE2 Cup TNMIX ISIC
Dice IoU Dice IoU Dice IoU Dice IoU
SAMed [40] 89.9 81.8 80.7 70.8 78.9 71.2 87.4 78.9
SAM-Med2D [10] 92.1 83.7 82.0 75.3 80.3 73.6 87.8 78.3
SAM-U [41] 91.2 82.4 81.5 73.2 79.8 74.0 88.7 79.6
VMN 92.5 83.9 82.8 76.1 81.4 74.2 88.3 79.1
FCFI 95.5 88.3 85.7 77.7 84.3 75.7 89.6 81.5
MedSAM [2] 92.9 85.5 82.1 73.8 81.3 74.7 86.8 77.5
Medical SAM Adapter (Med-SA) [11] 97.1 89.2 86.2 78.5 85.4 77.5 91.8 83.0
Medical SAM 2 [15] 97.8 88.8 87.6 81.2 87.6 80.1 92.7 84.6
The ISIC column follows the source paper and corresponds to ISIC 2019; it should not be interpreted as an ISIC2016 matched result.
Table 4. Non-prompted structural references under the adopted dataset splits and metric pipeline. These methods do not use prompt inputs and are therefore used for task-context comparison rather than as matched prompt-based baselines. Values are percentages.
Table 4. Non-prompted structural references under the adopted dataset splits and metric pipeline. These methods do not use prompt inputs and are therefore used for task-context comparison rather than as matched prompt-based baselines. Values are percentages.
Method REFUGE2 ISIC2016 TNMIX
Disc Dice Disc IoU Cup Dice Cup IoU Dice IoU Dice IoU
FAT-Net [42] 91.8 84.8 80.9 71.5 90.7 83.9 80.8 73.4
ResUNet-style [43] 92.9 85.5 80.1 72.3 87.3 78.2 78.3 70.7
2D Swin-UNETR-style [44] 95.3 87.9 84.3 74.5 90.4 83.3 83.5 74.8
2D TransBTS-style [45] 94.1 87.2 85.4 75.7 89.7 81.2 83.5 75.1
nnU-Net [20] 94.7 87.3 84.9 75.1 94.6 83.6 84.2 76.2
Table 5. Ablation study of HBF and BCER. Dice/IoU are reported on REFUGE2, ISIC2016, and TNMIX; HD95 is additionally reported for REFUGE2 disc and ISIC2016 using the same saved prediction masks and metric pipeline.
Table 5. Ablation study of HBF and BCER. Dice/IoU are reported on REFUGE2, ISIC2016, and TNMIX; HD95 is additionally reported for REFUGE2 disc and ISIC2016 using the same saved prediction masks and metric pipeline.
REFUGE2 ISIC2016 TNMIX
Method Disc Dice Disc IoU HD95 Cup Dice Cup IoU Dice IoU HD95 Dice IoU
Without HBF and BCER 93.8 86.2 35.9 82.1 73.8 87.5 78.6 31.3 81.6 75.1
Without HBF 94.6 89.2 23.5 86.0 76.1 92.4 87.4 41.6 86.4 78.0
Without BCER 95.0 90.9 13.9 85.6 76.9 92.9 87.9 42.5 87.1 78.5
HBF-BCER 95.4 91.3 6.5 91.0 83.7 95.9 92.4 28.0 91.4 85.1
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

© 2026 MDPI (Basel, Switzerland) unless otherwise stated

Accessibility

Disclaimer

Terms of Use

Privacy Policy

Privacy Settings