Package: napari-aisegcell
napari-aiSEGcellAnapariplugin to segment cell nuclei and whole cells in bright field microscopy images.napari-aisegcellusesaisegcellfor segmentation. This plugin can only be used to use already trained models for segmentation. If you
want to train a new model useaisegcell. Please citethis paperif you are using this plugin in your
research.Thisnapariplugin was generated withCookiecutterusing@napari'scookiecutter-napari-plugintemplate.ContentsInstallationCommand lineOne-clickDataDocumentationFirst launchLaunch napariLayer modeBatch modeTrained modelsImage annotation toolsCitationContributingLicenseIssuesInstallationThere are two ways to installnapari-aisegcell: First, you can installnapari-aisegcellfrom command line. Second, you
havenaparialready installed as a graphical user interface (GUI) and installnapari-aisegcellfrom the GUI menu.We recommend thecommand lineinstallation as it provides fine-grained control of the
installation to prevent conflicts with existing napari plugins. Use theone-clickinstallation if
you do not want to concern yourself with virtual environments or the command line. Just be aware that using theone-clickinstallation may introduce conflicts with already installed plugins or new plugin installations
may disrupt this plugin.napari-aisegcellwas tested withOS=macOS12.6.3/ubuntu22.10/windows10python=3.8.6torch=1.10.2torchvision=0.11.3
pytorch-lightning=1.5.9Command linenaparimust be installed from command line to installnapari aisegcellfrom command line. Installation requires a
command line application (e.g.Terminal) withgitandpythoninstalled. If you do not have python installed
already, we recommend installing it using theAnaconda distribution.
If you operate onWindowswe recommend usingAnaconda Powershell Promptas command line application.
An introductory tutorial on how to usegitand GitHub can be foundhere.(Optional) If you alreadyinstalled napariin avirtual environmentyou can skip this step.
However, you may want to installnapari-aisegcellin a fresh environment to avoid conflicts with existing
plugins. Create a new virtual environment fornapari.Hereis a
list of different python virtual environment tools. Open your command line application and create a (e.g.conda)
virtual environmentcondacreate-nnaparipython=3.8Activate your virtual environment that hasnapariinstalled or you want to installnaparitocondaactivatenapari(Optional) Installnapari. Skip this step if you havenaparialready installed.pipinstall"napari[all]"(Optional) If you useAnaconda Powershell Prompt, installgitthroughcondacondainstall-canacondagitInstallnapari-aisegcellfromPyPIpipinstallnapari-aisegcellfrom GitHub (= latest development version)pipinstallgit+https://github.com/CSDGroup/napari-aisegcell.gitWith step 4) completed you have successfully installednapari-aisegcell. You can proceed with thedocumentationon how to usenapari-aisegcell.NOTE, that when opening the plugin for the
first time, the remaining dependencies (torch, torchvision, pytorch-lightning) will be automatically installed
vialight-the-torch. If you prefer to manually install the remaining
dependencies (i.e. prevent potential interference with your virtual environment), proceed with step 5).(Optional)GPUsgreatly speed up training and inference ofaisegcelland are available fortorch(v1.10.2)
forWindowsandLinux. Check if yourGPU(s)are CUDA compatible
(Windows,Linux) and
update their drivers if necessary.(Optional)Installtorch/torchvisioncompatible with your
system.aisegcellwas tested withtorchversion1.10.2,torchvisionversion0.11.3, andcudaversion11.3.1. Depending on your OS, yourCPUorGPU(andCUDAversion) the installation may change# Windows/Linux CPUpipinstalltorch==1.10.2+cputorchvision==0.11.3+cpu-fhttps://download.pytorch.org/whl/cpu/torch_stable.html# Windows/Linux GPU (CUDA 11.3.X)pipinstalltorch==1.10.2+cu113torchvision==0.11.3+cu113-fhttps://download.pytorch.org/whl/cu113/torch_stable.html# macOS CPUpipinstalltorch==1.10.2torchvision==0.11.3(Optional)Installpytorch-lightning.aisegcellwas tested with
version1.5.9.# note the installation of v1.5.9 does not use pip install lightningpipinstallpytorch-lightning==1.5.9One-click(NOT YET AVAILABLE) Using the one-click installation ofnapari-aisegcellis as easy as openingnapari, selectingPlugins>Install/Uninstall Plugins...and searching fornapari-aisegcellin the search bar. Selectinstalland
restartnaparifornapari-aisegcellto appear in the list of installed plugins in thePluginsmenu. Please
recall that one-click installingnapari-aisegcellmay interfere with existing plugin installations or new
plugin installations may interfere with thenapari-aisegcellplugin.Datanapari-aisegcellis currently intended for single-class semantic and instance segmentation. Input images are expected
to be 8-bit or 16-bit greyscale images. Segmentation masks are expected to decode background as 0 intensity and all intensities
>0 are converted to a single intensity value (255). Have a look atthis notebookfor a data example.Documentationnapari-aisegcellhas two modes: Thelayer modeand thebatch mode. Layer mode is
intended to explore if existing trained models innapari-aisegcellare suitable for your data. Batch mode is
intended for high-throughput image segmentation once you have confirmed that existing models are well suited for
your data.First launchThe first time you launchnapari-aisegcell,torch, torchvision, pytorch-lightningwill be automatically
installed if you have skipped steps 5)-7) of theinstallation. The napari window will freeze
during download and installation. Depending on your setup this may take several minutes (~GBs of download). Similarly,
the first time you are running a pre-trained model the model weights (.CKPT file) will be downloaded and will
delay the prediction (~MBs of download).Launch napariThenaparibundled app is launched by opening the desktop shortcut. To launch napari as a command line
applicationOpen the terminal and activate the environment you installednapari-aisegcellintocondaactivatenapariRunnapariin terminalnapariLayer modeOpen the layer mode in the menuPlugins>napari-aisegcell>Layer mode. Select the parameters you want to use to
obtain your segmentation and select theRunbutton.Data sectionIn the Data section (magenta) you can select the images you want to segment from a drop-down menu. Only images that are
loaded in thenaparilayer tabare available for selection.
Image formats must be readable byskimage.io.imread.Neural network sectionIn the neural network section (cyan) you can select the neural net you want to use for segmentation. The section
has three parametersModel typeNucSeg: Select this option to use a pre-trainedaisegcellmodel to segment nuclei (seetrained models).CellSeg: Select this option to use a pre-trainedaisegcellmodel to segment whole cells (seetrained models).Custom: Select this option if you want to load aaisegcellmodel that does not ship withnapari-aisegcell.
Custom models can be obtained by training your ownaisegcellmodel or obtainingaisegcellmodels from 3rd
parties. You must select the checkpoint (.ckpt) file in the emergingCustom Modelparameter.Pre-trained Model: Drop-down menu to select the available pre-trained models forNucSegorCellSeg.Bright Field: a model to segment nuclei/whole cells in bright field. Currently, no other image modalities
are available.Computing Device: Drop-down menu that lists computing devices (CPU/GPUs) available with your currenttorchinstallation.Post-processing sectionIn the post-processing section (green) a selection of common post-processing steps are availableInstance Segmentation: Check this box to return instance segmentations instead of semantic segmentations.Remove Holes <: Removes holes in objects (e.g. nuclei) <X pixels.Minimum object size: Removes objects of size <X pixels before the dilation step.Maximum object size: Removes objects of size >X pixels before the dilation step.Dilation: Dilate (>0) or erode (<0) objects by X pixels (seehere).Batch modeOpen the batch mode in the menuPlugins>napari-aisegcell>Batch mode. Select the parameters you want to use to
obtain your segmentations and select theRunbutton.Theneural network sectionandpost-processing-sectionare
the same as in the layer mode.Data sectionIn the data section (magenta) you can select the images you want to submit for batch processing.InputSelect file: Select an existing input CSV file that follows theaisegcell input formatCreate file: Create a CSV file that follows theaisegcell input formatInput directory: Select parent directory containing all images to segment. Images can be in subdirectories.File pattern: All files matching this pattern in your selectedInput directorywill be stored in the CSV file.
Usewildcard characterslike*to capture all images
you want to segment in one run.Example 1*/*.png: will select allPNGfiles in in all sub-directories ofInput directory.Example 2position*z1.png: will select all files inInput directorythat start with "position" and
end with "z1.png"Save as: Name (and path) of the file that will be the input to your selected Neural Network. The file
can be used as input toSelect file.Mask suffix: Mask suffix that will be appended to each mask file name.Examplesuffix = "_mask":my_image.png->my_image_mask.pngOutput:Directory: Directory to which all segmentation masks will be saved. Be aware that input images with
identical file names will be appended withMask suffixAND an ID.CSD format: Store segmentation masks following the storage system of theCell Systems Dynamics group.
CSD format finds the deepest common directory of all input images, creates folders 'Analysis/Segmentation_YYMMDD',
and reconstructs the unique parts of all input paths in "Segmentation_YYMMDD".Trained modelsWe provide trained models:modalityimage formatmodelexample imagedescriptionavailabilitybright field nucleus segmentation2D grayscaleU-NetTrained on a data set (link to data set) of 9849 images (~620k nuclei).ETH Research Collectionbright field whole cell segmentation2D grayscaleU-NetTrained on a data set (link to data set) of 224 images (~12k cells).ETH Research CollectionImage annotation toolsAvailable tools to annotate segmentations include:napariLabkitforFijiQuPathilastikCitationt.b.d.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 theBSD-3license,
"napari-aisegcell" is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.