Skip to main content

StarDist - Object Detection with Star-convex Shapes

Project description

PyPI version Test Test (PyPI) Image.sc forum

StarDist - Object Detection with Star-convex Shapes

This repository contains the Python implementation of star-convex object detection for 2D and 3D images, as described in the papers:

Please cite the paper(s) if you are using this code in your research.

Overview

The following figure illustrates the general approach for 2D images. The training data consists of corresponding pairs of input (i.e. raw) images and fully annotated label images (i.e. every pixel is labeled with a unique object id or 0 for background). A model is trained to densely predict the distances (r) to the object boundary along a fixed set of rays and object probabilities (d), which together produce an overcomplete set of candidate polygons for a given input image. The final result is obtained via non-maximum suppression (NMS) of these candidates.

The approach for 3D volumes is similar to the one described for 2D, using pairs of input and fully annotated label volumes as training data.

Webinar/Tutorial

If you want to know more about the concepts and practical applications of StarDist, please have a look at the following webinar that was given at NEUBIAS Academy @Home 2020:

webinar video

Installation

This package is compatible with Python 3.6 - 3.9.

If you only want to use a StarDist plugin for a GUI-based software, please read this.

  1. Please first install TensorFlow (either TensorFlow 1 or 2) by following the official instructions. For GPU support, it is very important to install the specific versions of CUDA and cuDNN that are compatible with the respective version of TensorFlow. (If you need help and can use conda, take a look at this.)

  2. StarDist can then be installed with pip:

    • If you installed TensorFlow 2 (version 2.x.x):

      pip install stardist
      
    • If you installed TensorFlow 1 (version 1.x.x):

      pip install "stardist[tf1]"
      

Notes

  • Depending on your Python installation, you may need to use pip3 instead of pip.
  • You can find out which version of TensorFlow is installed via pip show tensorflow.
  • We provide pre-compiled binaries ("wheels") that should work for most Linux and Windows platforms, and also recent versions of macOS (Catalina/10.15 or later). If you're having problems, please see the troubleshooting section below.
  • (Optional) You need to install gputools if you want to use OpenCL-based computations on the GPU to speed up training.
  • (Optional) You might experience improved performance during training if you additionally install the Multi-Label Anisotropic 3D Euclidean Distance Transform (MLAEDT-3D).

Usage

We provide example workflows for 2D and 3D via Jupyter notebooks that illustrate how this package can be used.

Pretrained Models for 2D

Currently we provide some pretrained models in 2D that might already be suitable for your images:

key Modality (Staining) Image format Example Image Description
2D_versatile_fluo 2D_paper_dsb2018 Fluorescence (nuclear marker) 2D single channel Versatile (fluorescent nuclei) and DSB 2018 (from StarDist 2D paper) that were both trained on a subset of the DSB 2018 nuclei segmentation challenge dataset.
2D_versatile_he Brightfield (H&E) 2D RGB Versatile (H&E nuclei) that was trained on images from the MoNuSeg 2018 training data and the TNBC dataset from Naylor et al. (2018).

You can access these pretrained models from stardist.models.StarDist2D

from stardist.models import StarDist2D 

# prints a list of available models 
StarDist2D.from_pretrained() 

# creates a pretrained model
model = StarDist2D.from_pretrained('2D_versatile_fluo')

And then try it out with a test image:

from stardist.data import test_image_nuclei_2d
from stardist.plot import render_label
from csbdeep.utils import normalize
import matplotlib.pyplot as plt

img = test_image_nuclei_2d() 

labels, _ = model.predict_instances(normalize(img))

plt.subplot(1,2,1)
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.title("input image")

plt.subplot(1,2,2)
plt.imshow(render_label(labels, img=img))
plt.axis("off")
plt.title("prediction + input overlay")

Annotating Images

To train a StarDist model you will need some ground-truth annotations: for every raw training image there has to be a corresponding label image where all pixels of a cell region are labeled with a distinct integer (and background pixels are labeled with 0). To create such annotations in 2D, there are several options, among them being Fiji, Labkit, or QuPath. In 3D, there are fewer options: Labkit and Paintera (the latter being very sophisticated but having a steeper learning curve).

Although each of these provide decent annotation tools, we currently recommend using Labkit (for 2D or 3D images) or QuPath (for 2D):

Annotating with LabKit (2D or 3D)

  1. Install Fiji and the Labkit plugin
  2. Open the (2D or 3D) image and start Labkit via Plugins > Segmentation > Labkit
  3. Successively add a new label and annotate a single cell instance with the brush tool (always check the override option) until all cells are labeled
  4. Export the label image via Save Labeling... and File format > TIF Image

Additional tips:

  • The Labkit viewer uses BigDataViewer and its keybindings (e.g. s for contrast options, CTRL+Shift+mouse-wheel for zoom-in/out etc.)
  • For 3D images (XYZ) it is best to first convert it to a (XYT) timeseries (via Re-Order Hyperstack and swapping z and t) and then use [ and ] in Labkit to walk through the slices.

Annotating with QuPath (2D)

  1. Install QuPath
  2. Create a new project (File -> Project...-> Create project) and add your raw images
  3. Annotate nuclei/objects
  4. Run this script to export the annotations (save the script and drag it on QuPath. Then execute it with Run for project). The script will create a ground_truth folder within your QuPath project that includes both the images and masks subfolder that then can directly be used with StarDist.

To see how this could be done, have a look at the following example QuPath project (data courtesy of Romain Guiet, EPFL).

Multi-class Prediction

StarDist also supports multi-class prediction, i.e. each found object instance can additionally be classified into a fixed number of discrete object classes (e.g. cell types):

Please see the multi-class example notebook if you're interested in this.

Troubleshooting & Support

  1. Please first take a look at the frequently asked questions (FAQ).
  2. If you need further help, please go to the image.sc forum and try to find out if the issue you're having has already been discussed or solved by other people. If not, feel free to create a new topic there and make sure to use the tag stardist (we are monitoring all questions with this tag).
  3. If you have a technical question related to the source code or believe to have found a bug, feel free to open an issue, but please check first if someone already created a similar issue.

Installation

If pip install stardist fails, it could be because there are no compatible wheels (.whl) for your platform (see list). In this case, pip tries to compile a C++ extension that our Python package relies on (see below). While this often works on Linux out of the box, it will likely fail on Windows and macOS without installing a suitable compiler. (Note that you can enforce compilation by installing via pip install stardist --no-binary :stardist:.)

Installation without using wheels requires Python 3.6 (or newer) and a working C++ compiler. We have only tested GCC (macOS, Linux), Clang (macOS), and Visual Studio (Windows 10). Please open an issue if you have problems that are not resolved by the information below.

If available, the C++ code will make use of OpenMP to exploit multiple CPU cores for substantially reduced runtime on modern CPUs. This can be important to prevent slow model training.

macOS

The default Apple C/C++ compiler (clang) does not come with OpenMP support and the package build will likely fail. To properly build stardist you need to install an OpenMP-enabled GCC compiler, e.g. via Homebrew with brew install gcc (e.g. installing gcc-10/g++-10 or newer). After that, you can build the package like this (adjust compiler names/paths as necessary):

CC=gcc-10 CXX=g++-10 pip install stardist

If you use conda on macOS and after import stardist see errors similar to the following:

Symbol not found: _GOMP_loop_nonmonotonic_dynamic_next

please see this issue for a temporary workaround.

Apple M1

For installation of tensorflow and stardist on Apple M1 architecture, please see this excellent post by Peter Sobolewski.

Windows

Please install the Build Tools for Visual Studio 2019 from Microsoft to compile extensions for Python 3.6 and newer (see this for further information). During installation, make sure to select the C++ build tools. Note that the compiler comes with OpenMP support.

Plugins for other software

ImageJ/Fiji

We currently provide a ImageJ/Fiji plugin that can be used to run pretrained StarDist models on 2D or 2D+time images. Installation and usage instructions can be found at the plugin page.

Napari

We made a plugin for the Python-based multi-dimensional image viewer napari. It directly uses the StarDist Python package and works for 2D and 3D images. Please see the code repository for further details.

QuPath

Inspired by the Fiji plugin, Pete Bankhead made a custom implementation of StarDist 2D for QuPath to use pretrained models. Please see this page for documentation and installation instructions.

Icy

Based on the Fiji plugin, Deborah Schmidt made a StarDist 2D plugin for Icy to use pretrained models. Please see the code repository for further details.

KNIME

Stefan Helfrich has modified the Fiji plugin to be compatible with KNIME. Please see this page for further details.

How to cite

@inproceedings{schmidt2018,
  author    = {Uwe Schmidt and Martin Weigert and Coleman Broaddus and Gene Myers},
  title     = {Cell Detection with Star-Convex Polygons},
  booktitle = {Medical Image Computing and Computer Assisted Intervention - {MICCAI} 
  2018 - 21st International Conference, Granada, Spain, September 16-20, 2018, Proceedings, Part {II}},
  pages     = {265--273},
  year      = {2018},
  doi       = {10.1007/978-3-030-00934-2_30}
}

@inproceedings{weigert2020,
  author    = {Martin Weigert and Uwe Schmidt and Robert Haase and Ko Sugawara and Gene Myers},
  title     = {Star-convex Polyhedra for 3D Object Detection and Segmentation in Microscopy},
  booktitle = {The IEEE Winter Conference on Applications of Computer Vision (WACV)},
  month     = {March},
  year      = {2020},
  doi       = {10.1109/WACV45572.2020.9093435}
}

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

stardist-0.8.1.tar.gz (879.1 kB view details)

Uploaded Source

Built Distributions

stardist-0.8.1-cp39-cp39-win_amd64.whl (803.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

stardist-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

stardist-0.8.1-cp39-cp39-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

stardist-0.8.1-cp38-cp38-win_amd64.whl (804.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

stardist-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

stardist-0.8.1-cp38-cp38-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

stardist-0.8.1-cp37-cp37m-win_amd64.whl (804.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

stardist-0.8.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

stardist-0.8.1-cp37-cp37m-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

stardist-0.8.1-cp36-cp36m-win_amd64.whl (803.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

stardist-0.8.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

stardist-0.8.1-cp36-cp36m-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.6m macOS 10.15+ x86-64

File details

Details for the file stardist-0.8.1.tar.gz.

File metadata

  • Download URL: stardist-0.8.1.tar.gz
  • Upload date:
  • Size: 879.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1.tar.gz
Algorithm Hash digest
SHA256 2bcef9f627078abb22e365879f03e88bb8a588d41e94f82af07d787e56c823ed
MD5 825802cab3c095fe46876b865c4a8a65
BLAKE2b-256 42870f118e92b8b7ac4f496e8f74c4d0349782e73e3531bcf38ada0afcf0a070

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 803.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 661c8de539d00eef0a841ede477ebd82980cb52a51aa8df1bdffa1b6a2c21eb3
MD5 36e7555788044d6bea56a6c878f5225f
BLAKE2b-256 847e4c86b75393fb7252481c34837339f561100157379dbfd0420dfe355e2fd0

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stardist-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83f067e048497d6fbae985c5dd5036e511c2ad3e99cb9b496c691c3594556f75
MD5 020aa0a4a1ed17ea9d3a23730eb8c60e
BLAKE2b-256 3bb541ffc9140414c4608458cdcbb92f328b60c504bf7115961a69c36a4e54ff

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 47f67d6e77f8a1f3280e66a455469b776e5388717efb2986c17bbd16632bd9b9
MD5 a2cfeb803cffe6bba81b876e4ebc7045
BLAKE2b-256 3c682d4b082e26d2dd1a6c10efd6da46e03519cb729866b325ac8883c80d196a

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 804.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c0a29e540bc9891518cb5c64e9b41bcce1a886f952b7a7d08fd2e4e6e6408adc
MD5 63cfc8566dfac14e7c04773327354124
BLAKE2b-256 4219e08b76cd3aebfa1f13a4a6f545cb099aa1579a973bac494ea150e03311cb

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stardist-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 20fd71f5039347260737571c0d6d23c2a0d743fd25f7df247bcd9a3090098142
MD5 54e54c05c87e0100e379c19b2ee85b10
BLAKE2b-256 f0ab5d3f84867f7a2cf5f8593afed8d293cafcf4a4e109483633447e9213a380

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 cb906204bc5a571e2e421f63f95a6dd52e7d71a3e4a9cff213f17850c15e1dc6
MD5 52394782fde2d783a997b1474bd37640
BLAKE2b-256 c9cdd0f302fd7209db5d2b2d3564d693222568176f05dfc8b12433c237c2801d

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 804.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b3df6b25d4f41c100747b9e3ff4719a7cacf2ba38e13505a368e0944ba9373da
MD5 6fe6c531d3ae661a3bc48c7e393b46d8
BLAKE2b-256 b8b4710c4dcd19c02db5d368ad2ee6631fc37676498c0023f12735a0db4de8fc

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stardist-0.8.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28c2e8f183019ba34f3fc07c99723aea4975a9801260ed573e980fde9c2ec4aa
MD5 8d3ac761965c6e10d15c6512dee3bf8b
BLAKE2b-256 cab8a9026269b4e900423e3641475ac6a4b02e7dcd126d729dbc7a2d9f3d2ae6

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 62d2aca5668c2400cf21f20abb1b1e83392279ea66a5736f46f6ce615cf66fee
MD5 a70e01e271f1295d33797606de420dfc
BLAKE2b-256 510ea4bcda9dc4cf609af4a44f53fb39c363663e20d79f9e1974b04c8f0e7a7f

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 803.8 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5ba531b9f6054e5b16c8c517d2d39baea869ac3a95c9f4e3a7550c6cb1de0a06
MD5 aaf8d962e79c3f16d3f98661e334aa75
BLAKE2b-256 4475ce10765c571ce670bce4851f5933fe40df58ca6ea17274075e77b53a371f

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stardist-0.8.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99b0d333108964a0df644c5babbd9ca01d4fd56ad28ec508b5bfe7d0c1ee267e
MD5 40d9190414775853c3947cd1e741938e
BLAKE2b-256 0a1d774a74839bc7623bcd1395627ec75e06410658bab3b65696c89d59a51379

See more details on using hashes here.

File details

Details for the file stardist-0.8.1-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: stardist-0.8.1-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for stardist-0.8.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 28fd1412213b063fee2500f91ebacc1d183cc1601277f007ede70caf1b9d59a6
MD5 2a1384bac8508cd0bd03d569f2300e28
BLAKE2b-256 ad35b9bd529de076d597b1fcd8a5a5cda457a996bdb79a98e6087fad56a640f7

See more details on using hashes here.

Supported by

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