This project demonstrates how to use the Segment Anything Model (SAM) from the ultralytics
library for image segmentation. The script downloads an image, applies SAM to perform segmentation, and saves the segmented image locally.
For a step-by-step guide and code explaination, check out follow this tutorial
- Download an image from a URL.
- Perform image segmentation using the SAM model.
- Annotate and visualize the segmentation results.
- Save the segmented image locally.
- Python 3.x
ultralytics
(for the SAM model)supervision
(for handling detection annotations)opencv-python
(for image reading, saving, and processing)
You can install the required libraries using pip:
pip install -r requirements.txt
The script performs the following steps:
- Downloads an image from the specified URL.
- Loads the SAM model using ultralytics.
- Processes the image and performs segmentation using the SAM model.
- Annotates the detected segments (masks and bounding boxes) on the original image.
Saves the segmented image locally.