StarDist

repository·main·Indexed 23 days ago

https://github.com/stardist/stardist

A Python implementation for star-convex object detection in 2D and 3D images, primarily used for cell and nuclei segmentation in microscopy and histopathology. It supports multi-class training, big data prediction via tiling, and integration with tools like ImageJ/Fiji, QuPath, Napari, and Icy. The library provides pretrained 2D models and utilities for computing instance segmentation metrics via the stardist.matching submodule.

Tokens
7.1K
Snippets
26
Records
52
Agent score
79%

What's inside StarDist

  1. StarDist plugins for other software

    main

    StarDist is available as a plugin for several scientific imaging and data analysis platforms:

    • ImageJ/Fiji: Run pretrained 2D or 2D+time models. Plugin Page.
    • Napari: Python-based multi-dimensional viewer supporting 2D and 3D. Repository.
    • QuPath: Custom implementation of StarDist 2D for histopathology. Documentation.
    • Icy: StarDist 2D plugin. Repository.
    • KNIME: Modified Fiji plugin for KNIME compatibility. KNIME Hub.
  2. Access StarDist example notebooks

    main

    Because GitHub may have issues rendering Jupyter notebooks, it is recommended to view the StarDist examples via NBViewer or directly in the repository. The examples are categorized into 2D and 3D workflows, as well as specialized use cases like multi-class prediction, big data prediction, and model export.

    https://nbviewer.jupyter.org/github/stardist/stardist/tree/main/examples/
  3. Install and build Qhull with CMake

    main

    If you prefer using CMake (version 2.6 or later), follow these steps to build Qhull, its static/shared libraries, and the C++ interface:

    1. Download and extract the source.
    2. Navigate to the build directory.
    3. List available generators using cmake --help.
    4. Generate the build files using a specific generator and then run CMake: make -G "<generator>" .. && cmake .. (Note: The .. refers to the parent directory qhull/).
    5. Build the project with make.
    6. Install the project with make install.

    On Windows, CMake typically installs to C:/Program Files/qhull. 64-bit generators will include a Win64 tag.

    cd build
    cmake --help
    make -G "<generator>" .. && cmake ..
    cmake ..
    make
    make install
  4. Install StarDist

    main

    StarDist is compatible with Python 3.6 - 3.13. Installation requires TensorFlow to be installed first.

    1. Install TensorFlow: Follow the official TensorFlow installation instructions. Ensure CUDA and cuDNN versions are compatible if using GPU support.
    2. Install StarDist via pip:
      • For TensorFlow 2.x: pip install stardist
      • For TensorFlow 1.x: pip install "stardist[tf1]"

    Optional enhancements:

    • Install gputools for OpenCL-based GPU acceleration during training.
    • Install MLAEDT-3D (Multi-Label Anisotropic 3D Euclidean Distance Transform) to improve training performance for 3D volumes.
    pip install stardist
  5. Install StarDist via pip

    main

    Standard installation is performed via pip install stardist. If wheels (.whl) are unavailable for your platform, pip will attempt to compile a C++ extension. This requires Python 3.6+ and a working C++ compiler (GCC, Clang, or Visual Studio).

    To force compilation from source, use:

    pip install stardist --no-binary :stardist:
    pip install stardist
  6. Predict on very large images (Big Data)

    main
    When working with datasets that exceed available memory, use the 'Big data prediction' pattern. This typically involves tiling the large image, performing prediction on individual tiles, and stitching the results back together to avoid memory errors.
  7. Install StarDist on macOS with OpenMP support

    main

    The default Clang compiler on macOS does not support OpenMP out of the box. To enable multi-core CPU acceleration, you can use a Homebrew-installed GCC or install libomp manually.

    Option 1: Using Homebrew GCC

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

    (Adjust gcc-12 to your installed version, e.g., gcc-13)

    Option 2: Fixing 'Symbol not found' errors with libomp If you encounter ImportError: dlopen(...): symbol not found in flat namespace ... during import, use the following sequence:

    brew install libomp
    
    libomp_root=$(brew --prefix libomp)
    export CFLAGS="$CFLAGS -I$libomp_root/include"
    export CXXFLAGS="$CXXFLAGS -I$libomp_root/include"
    export LDFLAGS="$LDFLAGS -Wl,-rpath,$libomp_root/lib -L$libomp_root/lib -lomp"
    
    pip install --no-binary stardist stardist
    CC=gcc-12 CXX=g++-12 pip install stardist
  8. Use Qhull as a command-line tool

    main

    Qhull is a general dimension convex hull program that reads points from stdin and outputs the smallest convex set containing those points to stdout. It also supports Delaunay triangulations, Voronoi diagrams, and halfspace intersections.

    Common CLI Tasks:

    • Compute convex hull of random points: Use rbox to generate points and pipe them to qconvex. rbox 10 | qconvex (computes the hull for 10 random points).
    • Write results to a file: Use the TO flag. rbox 10 | qconvex i TO file.
    • Get help: Execute qconvex to see a synopsis and examples.

    Note for Windows users: If an error occurs, Windows may send the error to stdout instead of stderr. Use the TO xxx syntax to redirect normal output to a specific file.

    rbox 10 | qconvex
    rbox 10 | qconvex i TO file