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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.9

stardist-0.7.0-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.0-cp38-cp38-win_amd64.whl (758.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

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

Uploaded CPython 3.8

stardist-0.7.0-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.0-cp37-cp37m-win_amd64.whl (758.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

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

Uploaded CPython 3.7m

stardist-0.7.0-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.0-cp36-cp36m-win_amd64.whl (758.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

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

Uploaded CPython 3.6m

stardist-0.7.0-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.0.tar.gz.

File metadata

  • Download URL: stardist-0.7.0.tar.gz
  • Upload date:
  • Size: 730.5 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.0.tar.gz
Algorithm Hash digest
SHA256 c932eda623761a9648b510f511ec28ba89282292be7f008e11713414e248db18
MD5 bae595c0726888692b7cb16f8b3e5f7a
BLAKE2b-256 0a18e45dd94bfa6d302f42c906571b1c5eb129c7b155bd6514e12e2ed91ee2a0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4f00960fdcb20055ba7e1d17b2cb34c6cd99ef918b8e85a97e248abec7d6f74a
MD5 ceee60106e31896decd1db40e13e4efd
BLAKE2b-256 a019c68daec19be3cc1653471745716ff459cb90a4ec294a772359d20717531c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d341777ee72539c8bf338d3c644856b7cc7889d1310c94a5e9f18539b92c58d1
MD5 ff63b650c4fa0bf0b86f8b5139336c26
BLAKE2b-256 89cb5b184a5f1e28aeb96627c2185cb652cd0df0581c6774d6d5d870d296e7a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 04871bdaf846f8f622fe8dfb8340d432a3be0b77c7b2196453d520f00f3898e1
MD5 b11f6c64ee676186059d42832535861a
BLAKE2b-256 df7da998d3bfede439c5f531b136cade2e557e13e1a218681815cfb4a9b8d91a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6cc730aa9e5c30850bae272b960ef7ab088fc00394f715e1b74ce1174a38f7d5
MD5 c9475abb09c9eb42db474b03db0aa9de
BLAKE2b-256 3caa06a8012c45d30572d779d54b3d050442b7750d0adad5aad0340f1398aaf3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf4fb46723676ccd3f4c6103a266f588946ea57c699864a5454f1fef0cff28c0
MD5 1762b65c3ceaa093c9918fdea87bff05
BLAKE2b-256 71fdb8cfb4879dfc71f39f1489e5c88a65380f12e1606608c0d0917f7473118a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 398c2debbfff89e0259ac3d5c97af586092c5d7c451a3de566b8963c2c3abf06
MD5 04471fc411030909fe284888a829c04f
BLAKE2b-256 e3bde9a1621fc8a265393ee02acb6ed4d0b46908eec6d36a00e06c4bdb2b2d9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0d045ed3c89c7bfd58329af6757a716431b32c4cd5a0c4b8cd109c0260d33f2e
MD5 60a10f567eaaf35ecf01d7dc752b44e9
BLAKE2b-256 80cd067b5a2cd9d0089c61d994be8bbfb5c8abd40912df6bfdb8b7aede5eb8d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d73569309dd698f6964648e608a5706ec64d83d6f0763fbd37ca4311d145011d
MD5 1f9388316eae37c3b5ccb8ed6210aee3
BLAKE2b-256 c9043547315260f5cf35853c905da58c711ee8b4d5bfc61a7ad08c56a0536b4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0841ef416909983b6e652e67b180d093de86cbd62c90b036be435de020051ff0
MD5 a27b937896d2673e81cd361769d1340f
BLAKE2b-256 15de079fa85ae6208047146da834352459a2143728261fc0f179153e29c2185b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 617a272382a571b01dc377687f1a5599834acdf0b0de9edafc45670c1f9c1ac0
MD5 0a36f74dfc2e2df8a8b6d79604602180
BLAKE2b-256 00bb5898d4f57a65dda7be3cb79e290380be3f30cc8c56ff50521e827b11aaf0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89e13957b9229e7c8fb59a9bec5639ed1de64289df46b0ebe6e922c16a48dcc4
MD5 e78924922c336ba2043877a73c139eb5
BLAKE2b-256 98588a3c80731e366c5a0146d5666fa4da231bb6a5db4ea5efd52feee9f19e24

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stardist-0.7.0-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.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f7312bdfdbd96da25dc5577a5d3fbb0dab9093377ae3e71a8f0e815004184f06
MD5 eb9b72121116626ad7df73b4f877a6a3
BLAKE2b-256 18e5eba961a6532017fc841c158087b132eb9ad6fa639d42faf18268ea5a8eef

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