Package: napari-SAM4IS
napari-SAM4ISnapari plugin for instance and semantic segmentation annotation using Segment Anything Model (SAM)This is a plugin fornapari, 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.Thisnapariplugin was generated withCookiecutterusing@napari'scookiecutter-napari-plugintemplate.InstallationTo use this plugin, you'll need to install thenaparimulti-dimensional image viewer and theSegment Anything Model (SAM)library.napari InstallationYou can install napari using pip:pip install "napari[all]"Alternatively, you can install napari and all of its dependencies with conda:conda install -c conda-forge napariFor more detailed instructions, please refer to thenapari installation guide.SAM InstallationYou can install SAM from theofficial GitHub repositoryusing pip:pip install git+https://github.com/facebookresearch/segment-anything.gitOr 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 theSAM installation guide.napari-SAM4IS InstallationYou can installnapari-SAM4ISviapip:pip install napari-SAM4ISTo install latest development version :pip install git+https://github.com/hiroalchem/napari-SAM4IS.gitUsagePreparationOpen an image in napari and launch the plugin. (Opening an image after launching the plugin is also possible.)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.In the widget that appears, select the model you want to use and click the load button. (The default option is recommended.)Next, select the image layer you want to annotate.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.)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.)AnnotationSelect the SAM-Box layer and use the rectangle tool to enclose the object you want to segment.An automatic segmentation mask will be created and output to the SAM-Predict layer.If you want to make adjustments, do so in the SAM-Predict layer.To accept or reject the annotation, press "a" or "r" on the keyboard, respectively.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.If you reject the annotation, the segmentation mask in the SAM-Predict layer will be discarded.After accepting or rejecting the annotation, the SAM-Predict layer will automatically reset to blank and return to the SAM-Box layer.SavingIf you have output to the labels layer, use napari's standard functionality to save the mask.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.)ContributingContributions are very welcome. Tests can be run withtox, please ensure
the coverage at least stays the same before you submit a pull request.LicenseDistributed under the terms of theApache Software License 2.0license,
"napari-SAM4IS" is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.