/samist

Segment Anything Model (SAM) Image Segmentation Tool - SAMIST. Python GUI for image segmentation using SAM by Meta AI.

Primary LanguagePythonGNU Affero General Public License v3.0AGPL-3.0

SAMIST

Segment Anything Model (SAM) Image Segmentation Tool. A python GUI for image segmentation using SAM by Meta AI.

Installation

  1. Clone this repository and navigate into its directory
  2. Install dependencies, i.e. using pip install -r requirements.txt
  3. Download a model checkpoint from Meta AI:
  1. Run the script using python main.py

Usage

SAMIST utilizes PySimpleGui, and has no command line interface. The GUI looks like this when the program is started:

samist0

  • Use the 'Device' dropdown to select between CUDA and CPU execution. Note that CPU execution is significantly slower.
  • Select the 'Model Type' using the dropdown. Ensure that the model type you selected corresponds to the checkpoint you are using, or the program will hang.
  • Click 'Browse Model' to open up a system dialog and select the model path.
  • To the right of the 'Image File' textbox, select 'Browse' to load find an image, then press 'Load Image' to load it for segmentation. The image thumbnail will then appear in the GUI. The GUI looks like this after an image is loaded:

samist

  • Use the 'Points per side', 'Stability Score Threshold' and 'Prediction IOU Threshold' to set mask generation parameters. Experiment to find what works best for your application.
  • Click 'Segment Loaded Image' to begin image segmentation. This and the 'Load Image' button will be grayed out while segmentation is in progress. The GUI looks like this after image segmentation:

samist2

  • If one or more masks were generated using your parameter set, the 'Select Masked Image' slider will appear on the GUI. Drag it to select a mask for viewing and export. Position zero will show the original image.
  • There are three ways to export a mask using SAMIST, all of which will bring up the system dialog:
    1. 'Save Mask': This will save the full resolution greyscale mask to an image file.
    2. 'Save Masked Image': This will save a copy of the image with the mask applied to it, i.e. a full-resolution version of the masked image as it appears in the GUI.
    3. 'Save Cropped Image': This will save a copy of the image with the mask applied to it and crop it to contents.

Afterword

I hope you find this tool both useful and simple to use. Please let me know if you encounter any issues or have any suggestions. The Segment Anything Model was created by Meta AI and is licensed under the Apache 2.0 license.