Skip to main content

StarDist

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:

    pip install stardist

Notes

  • Depending on your Python installation, you may need to use pip3 instead of pip.
  • 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

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).

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.

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.7.1.tar.gz (825.4 kB view details)

Uploaded Source

Built Distributions

stardist-0.7.1-cp39-cp39-win_amd64.whl (757.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9

stardist-0.7.1-cp39-cp39-macosx_10_15_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

stardist-0.7.1-cp38-cp38-win_amd64.whl (758.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8

stardist-0.7.1-cp38-cp38-macosx_10_15_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

stardist-0.7.1-cp37-cp37m-win_amd64.whl (758.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

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

Uploaded CPython 3.7m

stardist-0.7.1-cp37-cp37m-macosx_10_15_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

stardist-0.7.1-cp36-cp36m-win_amd64.whl (758.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

stardist-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.6m

stardist-0.7.1-cp36-cp36m-macosx_10_15_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.6m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: stardist-0.7.1.tar.gz
  • Upload date:
  • Size: 825.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1.tar.gz
Algorithm Hash digest
SHA256 0b89ee7208ba25818932d6dbabbc18aed5af3eeaf545835faee55aa540edf6c0
MD5 84ffd669ffa2bd4eca436bf26166d349
BLAKE2b-256 a8dd5c72bd6d85a1f396480dfe8fe73b9a1f18e28c1ebbb8f22797b2350a1afb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 757.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 086e6856fd2d2404d4737cf990ec3e7870b1b05c064eac22006f90c7437c7a0f
MD5 6b988d5bd1530ffb30e553203738cfec
BLAKE2b-256 4db6eda68a2b3de36e21ddff41b265db4febbfd7ecf3b395642ffff54390f07c

See more details on using hashes here.

File details

Details for the file stardist-0.7.1-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: stardist-0.7.1-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7afeef5d1ac9750002312384a14a0b412c5cae79c303c2e96c57a8c30959023b
MD5 7181c865910374d701781419dcf43a43
BLAKE2b-256 acbfedcd74cdf92defddfaec40edd7844afc8d111d69f856a71bc2f274f3c5ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 93ebbfd95bff6ad59b4846d2e9e6d8a020d33a30a6c80933f01f013f2e0b6d17
MD5 5b1725a2ce2d9c0b7d5138b4db3515aa
BLAKE2b-256 9701e21746ab312d9ac5244ae22518ee2e8eba58435ac72bab9635fdb2212f81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 758.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d4366ea0f2734ec9a22a5ddc0cd09784af195ef85f8e521fb1829b9ad2aaa848
MD5 06370d6e20e22b2a6da5dc1d778a2014
BLAKE2b-256 86a61286c548a0e184371cb389737e82aeb68a15a3b5792fcd0d93d6afa10e74

See more details on using hashes here.

File details

Details for the file stardist-0.7.1-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: stardist-0.7.1-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de565ba6258c7c01eec4bbd09e464b2175b365a865a22db4ca0b7714efd9d65d
MD5 e03377ad4e02483a0f70f48208ca025e
BLAKE2b-256 736a83c072255c801bf5ee1734aaf90ccba192b8b2407008ebed0085d72ef148

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9b62bdf2d5e14f6f528388fc947d4b4a8120d87568a14bde1ee2e761ec25fbfb
MD5 62b4094c7dcddfb174198141c0059031
BLAKE2b-256 0b0014dda8d385432bdada9ca76c704a6c057e8092ff96b13537ca01a06af956

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 758.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6f80135a2c772d4958c0b9bea9c2a70b6e3f6f58f5ab32b73f0bb5da8c8102d3
MD5 7708af0a051292687bccfa9e79b9de37
BLAKE2b-256 6e188f92a519ace1bf66c0311d6a98e11a78fbf08eab0ab871d0673da4affa9d

See more details on using hashes here.

File details

Details for the file stardist-0.7.1-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: stardist-0.7.1-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28af9c731a108b18aab9107d7a2a94c803780e50bc022bb78850a29602807331
MD5 6bb4190fe4ed030963cafef26a429509
BLAKE2b-256 d763535bfa039f14a79160a8cb60f683a37a3ee9cb4c03424df13f8e97eefd61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f485e70d42390c3ed0e3089bb366cbbcbd1018a860f00c94a89123672cbb1c9c
MD5 2eb993a43022ae4f91d4ad1806e6cb06
BLAKE2b-256 76ae545a158cb23d7de613fd7991279466a7f160f0ec6a1dffe635b13a6055eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 758.2 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 258526b8b1add56e9c6a996710b8135c5634eb0bf0a7da0d632cc35f2d45d894
MD5 c7f288266631f935c1423cb710d2b8e6
BLAKE2b-256 ce869591b36ff201e674621d0aaa90786dbcbcc16cb391eee2905632e9d63c08

See more details on using hashes here.

File details

Details for the file stardist-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: stardist-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d26bdb6f972bda499b56a49ef6208961302d67db84134f745adb833a7d17d4f
MD5 f6c48d6f2e6467a0f0aaf60260da8e8b
BLAKE2b-256 cb6b9815fc2b2d35a3cd1f20f0992f4a3907e1d24a12c15e9358eac66dee149d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.1-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

File hashes

Hashes for stardist-0.7.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 36d2c7cc259ac20d601fe9eba6cd31f3d8c4e41f7c2959095166f39179cc8184
MD5 7c2ea35467c4ed981b0d0cb40d2eae98
BLAKE2b-256 c62af98f90bcd0d85d4a97425c73676c7962c333da3408a077f854d1b4483c14

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