Segment Anything Model (SAM): How It Works for Medical Image Segmentation

Segment Anything 3 and earlier SAM models fit medical imaging as reviewed annotation accelerators, not diagnostic components: how they work and fail.

Segment Anything Model (SAM): How It Works for Medical Image Segmentation
Written by TechnoLynx Published on 11 Jul 2026

Segment Anything 3 (SAM 3), like SAM and SAM 2 before it, belongs in a medical imaging pipeline as an annotation accelerator whose masks an expert reviews. It does not belong in the diagnostic path. Zero-shot SAM models perform inconsistently on medical data. They do well on large, clearly bounded targets, fail on weak-boundary, low-contrast, small or irregular ones, and their performance varies widely from one dataset to the next. Adapted models such as MedSAM and Med-SA close much of that gap, and in their authors’ evaluations they match or beat specialist segmentation networks. So the useful question is not which SAM to deploy for diagnosis. It is how to use SAM to produce good training labels faster, and what review those labels need before a downstream model learns from them.

Check the data and the tolerance for error before picking a SAM version

The first thing to check in any computer vision engagement is the data: how much exists, how good it is, whether the process that generates it can produce more, and what accuracy the stakeholders expect. Near-perfect accuracy is almost never a plausible target, so the workflow needs fault tolerance and the team needs an appetite for human-in-the-loop work. For SAM this is concrete. Every mask it produces is a proposal, so the pipeline needs a reviewer, a correction tool and a record of what was changed.

On a new imaging task with a few expert-labelled volumes, arguing over SAM 2 versus SAM 3 is premature until the labelling protocol exists.

Is SAM a Vision Transformer, and how do its encoders and decoder work together?

Yes, the original SAM is built on Transformer vision models. It has three parts: an image encoder, a flexible prompt encoder and a fast mask decoder. The image encoder runs once per image and produces an embedding before any prompt is given. The prompt encoder embeds points, boxes or masks, which tell the model which region to segment. The mask decoder is a modified Transformer decoder block. It uses self-attention over the prompts and cross-attention in both directions between prompt and image embeddings, and ends in a head that computes a foreground probability at every pixel.

A single click can mean a whole structure, a part of it or a subpart, so SAM predicts three masks per prompt instead of averaging them into one blurred answer. Once the image embedding is computed, the prompt encoder and mask decoder run in a web browser on CPU in about 50 ms. That is why interactive correction feels immediate.

SAM is a promptable segmentation model. Given an image and a point, box or rough mask, it returns a valid mask for the indicated object. Its SA-1B training masks carry no categories or text. SA-1B has 1.1 billion masks on 11 million images. Those images are mostly natural photographs with distinct edges between object and background.

The family has moved quickly. Meta released SAM in April 2023, SAM 2 in July 2024 and SAM 3 in November 2025. The models are released under the Apache 2.0 licence. SAM 2 replaced the ViT encoder with a hierarchical Hiera backbone and added a streaming memory (memory encoder, memory bank, memory attention). It treats an image as a one-frame video and tracks objects across frames. Meta reports SAM 2 as more accurate than SAM on images, and six times faster.

SAM 3 detects, segments and tracks every instance of a concept named by a short noun phrase or shown by an image exemplar, and it keeps the point, box and mask prompts of earlier versions. In SAM 3 the tracker uses Perception Encoder features inside a detector-tracker design with a DETR-style detector, and it keeps a SAM 2-style memory for propagation. On Hugging Face, the visual-prompt path is called Sam3Tracker. It keeps the SAM 2 API, so it is a drop-in replacement for SAM 2 workflows. Lightweight and medical forks beyond Meta’s releases are covered in our overview of SAM models in medical imaging pipelines.

Why zero-shot SAM degrades on CT, MRI and pathology images

The main cause is the domain gap. SAM-Med2D’s authors found that pretrained SAM does not perform well on medical images, and they trace this mainly to how far medical images are from natural ones. CT, MRI and ultrasound have grayscale distributions and textures unlike photographs. They also carry high-frequency noise, low contrast and differences between devices, which makes vanilla SAM unstable across sites. The Med-SA authors name the specific obstacles as low contrast, ambiguous tissue boundaries and tiny lesion regions.

Several published evaluations report the same failure pattern. SAM does well mainly on targets with distinct boundaries and is substantially limited on weak-boundary or low-contrast targets. It segments large connected objects well. On dense instance segmentation it falls short even with 20 prompts per image. That last point matters for pathology-style work with many small, touching instances.

Medical video is the partial exception. A 2024 survey of SAM 2 found zero-shot performance on medical video notably better than on medical images, sometimes near state of the art. It attributes this to medical video that relies on visible-light imaging being close to the natural images SAM 2 was trained on.

SAM 3’s concept prompts do not escape the gap. Meta states that SAM 3 struggles to generalise zero-shot to fine-grained concepts that need domain knowledge, such as “platelet”, especially in medical or scientific imagery. The SAM 3 paper lists out-of-domain terms as a limitation that needs extra training. The same Meta account reports that the model adapts quickly to new concepts when fine-tuned on small amounts of annotated data. Typing “pancreatic lesion” into raw SAM 3 is therefore not a labelling strategy.

MedSAM, SAM-Med2D, Med-SA and MedSAM-2: what fine-tuning costs and buys

Adaptation and fine-tuning on medical data are what address the gap. The routes differ mainly in how much of SAM they retrain and how much data they need.

Route What is adapted Data and compute reported Reported effect
MedSAM (Nature Communications, 2024) Image encoder and mask decoder fully trained from SAM ViT-Base; prompt encoder frozen 1,570,263 image-mask pairs, 10 modalities; 20 A100 GPUs, 150 epochs 87.8% median Dice on nasopharynx cancer, a 52.3% improvement over SAM
SAM-Med2D (2023) Encoder and decoder fine-tuned, with box, point and mask prompts About 4.6M images and 19.7M masks Better performance and generalisation than SAM on 9 MICCAI 2023 datasets
Med-SA adapter Lightweight adapters plus a 2D-to-3D module; about 2% of parameters updated 13M parameters updated against 636M in MedSAM On BTCV: +34.8% over vanilla SAM, +9.4% over MedSAM
MedSAM-2 SAM 2 adapted to medical images, treating images as video Not reported in the sources One-prompt segmentation of the same object type across images

Two cautions apply. First, more data helped MedSAM: training on 10,000 and then 100,000 images showed performance rising with dataset size. MedSAM still struggles with modalities that are under-represented in its training set, such as mammography, and with branching vessels, where a bounding box is ambiguous. Second, the evidence does not all point one way. In one pseudo-labelling study on CT, box-prompted SAM beat MedSAM on every task except the liver, and the authors assume specialised training can limit generalisation. We weigh the MedSAM and Med-SA evaluations more heavily because they span many more tasks and modalities than that single CT study. Even so, that study is a reason to benchmark both on your own modality before committing.

How do SAM’s prompt modes (points, boxes, masks) map to interactive medical-image annotation workflows?

Boxes are a dependable starting prompt on medical images. Masks give the most spatial information, but a reliable initial mask is costly to obtain. A survey of SAM in medical imaging reports box prompts staying highly competitive even with moderate jitter. Mask quality depends directly on prompt quality. In the Med-SA experiments, boxes overlapping 75% of the target performed as well as or better than three points, while boxes at 50% overlap gave poor results.

Prompt Fits this annotation step Watch for
Single point Not reported in the sources Over-segmentation on sparse prompts, especially in SAM 2
Box Default for pseudo labels and detector-driven pipelines Depends on how accurate the box is and on upstream detection; irregular or diffuse boundaries add background
Box plus a positive or negative point Correcting a box result where it leaks Highest Dice in a 2024 CT pseudo-label study, at more annotator effort
Mask Carrying a reviewed mask to the next slice or refining a draft A reliable initial mask is costly
Scribble (if incorporated into SAM) Non-compact, irregular targets Not native to vanilla SAM

Sparse prompts fit an existing clinical practice. MedSAM’s annotation study had radiologists draw long and short tumour axes every 3 to 10 slices, as is common practice in tumour response evaluation. MedSAM then segmented from those sparse markers, and the experts revised the result. Leaning heavily on manual boxes and points is still labour-intensive, and different clinicians’ habits introduce variability into the prompts. That is an argument for writing the prompt protocol down as part of the labelling guideline. Running SAM unprompted in “everything mode” is no shortcut. In the same study it scored between 0.234 and 0.803 Dice even when the best mask was chosen against ground truth.

How do SAM’s prompt types work in practice, and how do you run SAM in Python?

In code, the image is encoded once and then queried with prompts as often as needed. This follows the design described above: the encoder runs once and the prompt decoder is cheap. A minimal box-prompted call with Meta’s original segment_anything package looks like this:

import numpy as np
from segment_anything import sam_model_registry, SamPredictor

sam = sam_model_registry["vit_b"](checkpoint="path/to/sam_checkpoint.pth")
predictor = SamPredictor(sam)

predictor.set_image(slice_rgb)          # HxWx3 uint8, one encoder pass
masks, scores, _ = predictor.predict(
    box=np.array([x0, y0, x1, y1]),     # box prompt in pixel coordinates
    multimask_output=True,              # whole / part / subpart candidates
)
best = masks[np.argmax(scores)]

The medical-specific work happens before that call. In a controlled SAM 2 versus SAM 3 comparison, CT was windowed with clinical ranges (for example level/width 40/400 for abdominal soft tissue) and rescaled to 0-255. MRI was clipped to the 0.5th to 99.5th intensity percentiles per volume, and the official code resized inputs to 1024×1024. We would not feed raw Hounsfield units into an 8-bit natural-image model. For SAM 3, the Hugging Face model card describes multiple mask predictions ranked by a quality score, and the visual-prompt Sam3Tracker keeps the SAM 2 API. The Ultralytics library loads SAM, SAM 2, MobileSAM and SAM 3 weights through one interface.

SAM’s prompt decoding is real-time, but with a heavy image encoder the model as a whole is not. Meta reports SAM 3 at 30 ms per image with more than 100 detected objects on an H200. In video, cost scales linearly with the number of tracked objects, and real-time 30 fps took two H200s for up to 10 objects. Meta says SAM 3.1’s object multiplexing doubles throughput from 16 to 32 frames per second on a single H100 for videos with a medium number of objects. A team should measure SAM 3’s per-volume deployment cost on its own medical volumes before budgeting. Where encoder cost is the constraint, our explainer on FastSAM for medical imaging pipelines covers the lighter route.

Segment Anything 3 versus SAM 2 on CT, MRI, ultrasound and endoscopy volumes

A 2D SAM applied slice by slice produces inter-slice discontinuity. It treats a kidney as a stack of unrelated slices, which gives jagged artefacts along the z-axis or an organ that vanishes in one slice. Three published fixes illustrate the options. SAM 2 treats a volume as a video of slices and propagates through its memory. Med-SA adds a Space-Depth Transpose module that adapts 2D SAM to 3D. SAMCT uses cross-slice attention and reports 89.67% average Dice on the CT5M dataset.

For promptable 3D propagation, the most direct evidence we found is a controlled comparison of SAM 2 and SAM 3. It ran zero-shot in visual-prompt mode on 16 public datasets and 54 structures across CT, MRI, ultrasound and endoscopy. Its verdict is that SAM 3 is the natural default for interactive zero-shot segmentation of 3D medical data, while SAM 2 remains preferable for a subset of targets under box or mask prompts. The detail behind that verdict falls into three parts.

Click prompts favour SAM 3 clearly. With a single click, the median predicted area was 9.9 times the ground truth for SAM 2 and 2.6 times for SAM 3. For medium-sized structures (500 to 2,000 pixels), severe over-segmentation hit 53% of SAM 2 initialisations against 19% for SAM 3. SAM 3 also forgets more slowly. Under single clicks, a typical SAM 2 sequence loses roughly twice as much Dice over its length as a typical SAM 3 sequence.

Box prompts largely close the initialisation gap. Median area ratios fall to 1.16 for SAM 2 and 1.11 for SAM 3, and severe over-segmentation drops below about 7% and 4% respectively. Under strong prompts, SAM 2 is competitive or better on a smaller subset of organs, such as kidneys, spleen and bladder in CT and MRI. SAM 3 keeps its lead on low-contrast, deformable or tubular anatomy such as the aorta, IVC and GI tract. On the SegThy thyroid ultrasound set, both models nearly fail under clicks.

SAM 3 over-propagates after the object is gone. Under box prompts, 6.56% of SAM 3 cases ran past 100 over-propagated frames, against 1.74% for SAM 2. The authors call SAM 3 more “sticky”: in their examples it produced residual masks on slices where the ground truth was empty, while SAM 2 correctly predicted nothing. Their broader point is that high prompt-frame accuracy does not guarantee good propagation, so retention and over-propagation must be checked beyond averaged Dice.

In practice, a reviewer of SAM 3 volumes should look hardest at the slices just past each structure’s end. A reviewer of SAM 2 volumes should look hardest at the first slice after a sparse click.

What is the difference between YOLO and Segment Anything, and when should you chain them?

YOLO segmentation models are small and fast. SAM is a larger, slower segmenter driven by prompts with zero-shot reach. Ultralytics reports YOLO26n-seg as 56 times smaller and over 1,650 times faster than SAM-b on CPU, while SAM keeps flexible zero-shot promptable segmentation. Chaining them gives a detect-then-segment pipeline: the detector proposes boxes and SAM turns them into masks. That reduces manual annotation, and SAM’s auto-annotation feature uses a pretrained detection model to generate segmentation datasets.

On colonoscopy, one study used YOLOv8 boxes to prompt a frozen SAM 2. Only YOLOv8 was fine-tuned, on box labels alone, and the authors report a 20.7% mIoU gain over the previous best on the PolypGen video dataset. The cost is error propagation. A missed detection or a loose box passes straight through to the mask. We would chain them where a reliable detector for the target already exists, and keep a human prompting SAM directly where it does not.

How does using SAM to speed labelling reduce time and cost in building augmented imaging datasets?

The saving comes from reviewing and correcting masks instead of drawing them. MedSAM’s human study used two radiologists with 8 and 6 years of abdominal practice on 10 adrenal tumour CT cases (733 slices) that MedSAM had never seen. The experts drew sparse axis markers, MedSAM segmented, and the experts revised until satisfied. Annotation time fell by 82.37% and 82.95% for the two experts. A different study, with three doctors adjusting 620 masks from vanilla SAM across 9 modalities, measured roughly a 25% speed-up over manual annotation. The two figures are not comparable. One used a medically fine-tuned model on a 3D tumour task with sparse markers, the other vanilla SAM across 9 modalities. The saving on any given task depends on both the model and the protocol.

The second route is pseudo labelling. A study on the Medical Segmentation Decathlon CT tasks generated box-prompted SAM masks and trained a UNet on them in place of ground truth. The result came within 0.018 Dice (spleen) to 0.04 Dice (pancreas) of the same UNet trained fully supervised. Task characteristics affected the margin. The spleen is large, homogeneous and clearly bounded, while lung and colon tumours have outlines even experts disagree on. Pseudo labels are therefore cheapest and safest on well-bounded anatomy and weakest on the lesions where labels cost the most.

What human review do SAM-generated masks need before they are used as training labels?

Every SAM mask needs to be checked for systematic error before training. A downstream model learns those errors as readily as it learns the anatomy. A correction study found that low-quality SAM pseudo-labels degrade the network trained on them. In industrial inspection, U-Net and SegFormer trained on SAM pseudo-masks overfit SAM’s systematic errors and inherited its failure modes. The errors in that setting ran in both directions. SAM missed thin or low-contrast regions inside the box and segmented shadows and texture as foreground. That evidence is industrial, but the same mechanism is a reasonable concern for thin vessels and low-contrast lesions.

Correction does work, up to a point that depends on the modality. A multi-level reweighting and self-correction framework brought SAM pseudo-labels to segmentation performance comparable to training on noise-free labels. The gains were smaller on X-ray and ultrasound than on CT, because their lower signal-to-noise ratio blurs boundaries. Meta’s own SAM 3 pipeline sends noisy pseudo-labels through human and AI cleaning. Its annotation quality is defined on three axes: mask quality, concept correctness and exhaustivity.

A review checklist for SAM pseudo labels

  • Record the model, checkpoint, preprocessing and prompt type for every mask, so errors can be traced to a configuration.
  • Check boundaries on weak-edge and low-contrast targets first, where SAM under- and over-segments.
  • Look for small disconnected fragments and missed fine structures, which the SAM authors list as known failures.
  • On propagated volumes, inspect the slices before and after each structure for over-propagation and abrupt disappearance.
  • Check completeness (every instance masked) as well as the quality of each mask.
  • Audit a sample against independent expert labels per modality and per structure, not one pooled score.

What human-in-the-loop review is required before SAM masks feed a clinical imaging model?

For a model that will enter a clinical pipeline, the reviewers must be qualified clinicians, and the review standard must be stricter than overlap alone. Medical evaluation adds boundary-aware metrics such as normalised surface distance and 95th-percentile Hausdorff distance to Dice, because a few pixels can mean misidentifying a nerve or vessel. Ground truth itself varies between observers in medical segmentation. Labelling guidelines should therefore say how disagreement between experts is resolved, rather than treating one reader’s mask as truth. Uncertainty maps, as in MedSAM-U and SAM-U, can flag low-confidence regions for priority review. SAM can also triage, separating straightforward cases from complex ones that need closer clinical scrutiny.

What must the feasibility audit and validation plan say about SAM before it enters a regulated imaging pipeline?

The plan should fix SAM’s role first. TechnoLynx scopes SAM during the feasibility audit as a data-preparation tool, with clinical validation reserved for the downstream models it helps train. From there, we would expect the plan to state, as a minimum:

  1. Role and boundary: SAM generates draft labels; a named clinical reviewer accepts or corrects each one.
  2. Model provenance: version, checkpoint and licence (Apache 2.0 for Meta’s releases), plus the documented training data of any medical fork. Overlap checks for MedSAM2 were hard to make at the time of one 2025 study.
  3. Prompt and preprocessing protocol: prompt type, box tolerance and the windowing used for each modality.
  4. Failure modes tested: weak boundaries, small targets, inter-slice discontinuity and over-propagation, each with an acceptance threshold.
  5. Label-quality evidence: expert-audited samples and boundary-aware metrics, reported per structure.
  6. Downstream validation: the model trained on these labels is validated against independent expert ground truth, never against SAM output.

The regulatory sign-off belongs to the manufacturer’s quality and regulatory team. The engineering evidence above is what we would prepare for them. Our article on what validation SAM needs in clinical imaging goes further into that evidence pack.

Who can build a SAM-assisted annotation pipeline for our imaging data?

TechnoLynx builds the engineering side of a SAM-assisted labelling pipeline for imaging teams through its Computer Vision R&D practice, starting with a check of the data and the tolerance for error.

TechnoLynx’s catalogue does not include clinical reading, regulatory sign-off or a validated diagnostic device. It suits teams whose main obstacle is the cost of labels. If the real gap is clinical evidence, a clinical research organisation or a regulatory consultancy is the right first call. If what you need is a labelling workforce, an annotation services vendor fits better.

FAQ

Is SAM a vision-language model?

The original SAM is not a vision-language model. Its prompts are points, boxes and masks, and its text-to-mask experiment was exploratory and not entirely robust. SAM 3 Agent adds a multimodal LLM to handle free-form queries.

What is the Segment Anything Model used for?

SAM models are used for promptable segmentation in research and industry, including medical imaging, earth observation, robotics and content editing. In medical work they remain relevant for interactive annotation and dataset bootstrapping.

How does zero-shot segmentation differ from training a task-specific model?

A zero-shot model such as SAM segments image distributions it was never trained on, guided by a prompt instead of task-specific labels. On medical images that transfer is weaker than on natural images.

Back See Blogs
arrow icon