segmentAnythingModel
Description
Add-On Required: This feature requires one of these add-ons.
Use the segmentAnythingModel object to interactively segment
objects in an image using visual prompts, such as foreground points or bounding
boxes.
A segmentAnythingModel object configures
a pretrained Segment Anything Model 2 (SAM 2) or Segment Anything Model (SAM) for image
segmentation of objects in an image without retraining the model. To learn more about the
model and the training data, see the SA-V Dataset and
SA-1B Dataset
pages.
To segment objects in an image, you must first extract
the image embeddings from the SAM image encoder by using the extractEmbeddings
function. Then, segment objects from the image embeddings by using the segmentObjectsFromEmbeddings function.
Note
To use any of the SAM 2 models, this functionality requires the Image Processing Toolbox™ Model for Segment Anything Model 2 add-on if you use any of the SAM 2 models. To use the base SAM model, this functionality requires the Image Processing Toolbox Model for Segment Anything Model add-on.
Creation
Description
Input Arguments
Properties
Object Functions
extractEmbeddings | Extract feature embeddings from Segment Anything Model (SAM) encoder |
segmentObjectsFromEmbeddings | Segment objects in image using Segment Anything Model (SAM) feature embeddings |
Examples
Limitations
The SAM can have difficulty detecting and accurately segmenting objects of these types:
Objects with boundaries that are indistinct or blurry, such as those in low-resolution images.
Very small objects within a scene, particularly when they occupy only a few pixels.
References
[1] Kirillov, Alexander, Eric Mintun, Nikhila Ravi, Hanzi Mao, Chloe Rolland, Laura Gustafson, Tete Xiao, et al. "Segment Anything," April 5, 2023. https://doi.org/10.48550/arXiv.2304.02643.
[2] Ravi, Nikhila, Valentin Gabeur, Yuan-Ting Hu, Ronghang Hu, Chaitanya Ryali, Tengyu Ma, Haitham Khedr, et al. “SAM 2: Segment Anything in Images and Videos.” arXiv, October 28, 2024. https://doi.org/10.48550/arXiv.2408.00714.
Version History
Introduced in R2024aSee Also
Functions
imsegsam|extractEmbeddings|segmentObjectsFromEmbeddings|grabcut|superpixels|lazysnapping|watershed
Objects
medicalSegmentAnythingModel(Medical Imaging Toolbox)


