Skip to main content

Create annotations for instance segmentation using Segment Anything models

Project description

napari-SAM4IS

License Apache Software License 2.0 PyPI Python Version tests codecov napari hub

napari plugin for instance and semantic segmentation annotation using Segment Anything Model (SAM)

This is a plugin for napari, a multi-dimensional image viewer for Python, that allows for instance and semantic segmentation annotation. This plugin provides an easy-to-use interface for annotating images with the option to output annotations as COCO format.


This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.

Installation

Step 1: Install napari-SAM4IS

You can install napari-SAM4IS via pip:

pip install napari-SAM4IS

Or via conda

conda install -c conda-forge napari-SAM4IS

Step 2: Install Segment Anything Model

IMPORTANT: You must install the Segment Anything Model separately to use this plugin:

pip install git+https://github.com/facebookresearch/segment-anything.git

Development Installation

To install the latest development version:

pip install git+https://github.com/facebookresearch/segment-anything.git

Or you can install from source by cloning the repository:

git clone https://github.com/facebookresearch/segment-anything.git
cd segment-anything
pip install -e .

For more detailed instructions, please refer to the SAM installation guide.

napari-SAM4IS Installation

You can install napari-SAM4IS via pip:

pip install napari-SAM4IS

Or via conda

conda install -c conda-forge napari-SAM4IS

To install latest development version :

pip install git+https://github.com/hiroalchem/napari-SAM4IS.git

Usage

Preparation

  1. Open an image in napari and launch the plugin. (Opening an image after launching the plugin is also possible.)
  2. Upon launching the plugin, three layers will be automatically created: SAM-Box, SAM-Predict, and Accepted. The usage of these layers will be explained later.
  3. In the widget that appears, select the model you want to use and click the load button. (The default option is recommended.)
  4. Next, select the image layer you want to annotate.
  5. Then, select whether you want to do instance segmentation or semantic segmentation. (Note that for 3D images, semantic segmentation should be chosen in the current version.)
  6. Finally, select the output layer as "shapes" for instance segmentation or "labels" for semantic segmentation. (For instance segmentation, the "Accept" layer can also be used.)

Annotation

  1. Select the SAM-Box layer and use the rectangle tool to enclose the object you want to segment.
  2. An automatic segmentation mask will be created and output to the SAM-Predict layer.
  3. If you want to make adjustments, do so in the SAM-Predict layer.
  4. To accept or reject the annotation, press "a" or "r" on the keyboard, respectively.
  5. If you accept the annotation, it will be output as label 1 for semantic segmentation or converted to a polygon and output to the designated layer for instance segmentation.
  6. If you reject the annotation, the segmentation mask in the SAM-Predict layer will be discarded.
  7. After accepting or rejecting the annotation, the SAM-Predict layer will automatically reset to blank and return to the SAM-Box layer.

Saving

  1. If you have output to the labels layer, use napari's standard functionality to save the mask.
  2. If you have output to the shapes layer, you can save the shapes layer using napari's standard functionality, or you can click the "save" button to output a JSON file in COCO format for each image in the folder. (The JSON file will have the same name as the image.)

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the Apache Software License 2.0 license, "napari-SAM4IS" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

napari_sam4is-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

napari_sam4is-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file napari_sam4is-0.1.0.tar.gz.

File metadata

  • Download URL: napari_sam4is-0.1.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for napari_sam4is-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2daf9107bb6e991111177132116d097f1663dad0ce26c6b198f95e9b2943fa1c
MD5 b2a956fd129894c1048b31fe8158e973
BLAKE2b-256 a438ba1992fc0f4be5b3daf7274a8a6be37e3aef7a9585e376d16a3a916d90cb

See more details on using hashes here.

File details

Details for the file napari_sam4is-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: napari_sam4is-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for napari_sam4is-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60a150eba7835d6cfa9f188ca5d9da3ab42ce0123e6a61fbc4217ddd2aa2a5b9
MD5 ab4115c4acba9e4e5d9f557fcee68340
BLAKE2b-256 2ea7d2a397f982fb817e61e24c05d67ad986137a1192cfa53a7eb4eb19deeccf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page