Skip to content
/ SPROUT Public

Lightweight segmentation toolkit for fine-grained and multi-part segmentation of grayscale 2D/3D images, with napari support.

License

Notifications You must be signed in to change notification settings

EchanHe/SPROUT

Repository files navigation

SPROUT

A User-friendly, Scalable Toolkit for Multi-class Segmentation of Volumetric Images

Introduction

SPROUT (Semi-automated Parcellation of Region Outputs Using Thresholding and Transformation)
SPROUT is an interpretable workflow for semi-automated, multi-class segmentation of volumetric images (e.g., CT, MRI). It requires no training data and is designed for researchers facing challenging segmentation tasks, such as structures with fine details or weak boundaries, where data for deep learning is scarce.

Y. He, M. Camaiti, L.E. Roberts, J.M. Mulqueeney, E. Ioannou, M. Didziokas, A. Goswami. 2024.
SPROUT: A User-friendly, Scalable Toolkit for Multi-class Segmentation of Volumetric Images

👉 If you want to jump straight in, see: Quickstart with Demo Data.

Prerequisites

  1. Python and Environment Setup

    • Install Python: If Python is not already installed, we recommend downloading the Anaconda distribution. After providing your email, follow the download link and select the version suitable for your operating system.
    • Set up Python Environment:
      • For Windows users with Anaconda, open the Anaconda Prompt from the Start menu.
      • For other installations, open a terminal with Python access.
  2. Create and Configure Python Environment

    • SPROUT supports Python 3.10. Required libraries and versions are:
      NumPy: 1.26.4
      Pandas: 2.2.1
      Scikit-image: 0.22.0
      Tifffile: 2024.2.12
      imagecodecs: 2025.3.30
      Pyyaml: 6.0.1
      Trimesh: 4.3.1
      Matplotlib: 3.8.3
      open3d: 0.18.0
      
    • Steps to create the environment:
      1. Create the environment:
        conda create -n sprout python=3.10
      2. Activate the environment:
        conda activate sprout
      3. Install dependencies:
        pip install numpy==1.26.4 pandas==2.2.1 scikit-image==0.22.0 tifffile==2024.2.12 pyyaml==6.0.1 trimesh==4.3.1 matplotlib==3.8.3 open3d==0.18.0 imagecodecs==2025.3.30

Optional: Enable SproutSAM (Prompt-based Segmentation with SAM/SAM2)

SproutSAM is an optional module that enables prompt-based segmentation using foundation models like SAM and SAM2. If you wish to use SproutSAM, please install the following additional dependencies:

Core Dependencies

pip install torch torchvision torchaudio
pip install opencv-python-headless

⚠️ For optimal performance, we recommend using GPU-enabled PyTorch. You can find the correct installation command based on your system here:
https://pytorch.org/get-started/locally/

📦 Install Segment Anything Models

You also need to install the SAM and/or SAM2 libraries:

🧪 Recommended Visualization Tools

💡 Strongly recommended: napari
SPROUT comes with a napari plugin for interactive 2D/3D visualization and editing of seeds, segmentation results, and more.

To install napari and the SPROUT plugin (napari-sprout):

pip install napari
cd ./napari_sprout
pip install -e .

You can launch napari by running napari in the command line. The SPROUT plugin will appear under the Plugins menu in the napari UI.

⚙️ Usage

SPROUT follows a two-step workflow for multi-class segmentation:

workflow

  1. Seed Generation
    The goal of this step is to reduce the regions of the image by breaking it into multiple distinct components (splits). There are two strategies:

    • Vanilla seed generation: generate multiple seeds by varying configurations such as thresholds and erosion steps.
    • Adaptive seed generation: automatically combine information across seeds from different configurations to produce a often better and final seed.
  2. Seed Growth

    • Threshold-based growth: grows a seed by expanding the reduced components back toward their full target shapes. Growth is guided by image intensity and connectivity.
    • SproutSAM: seeds are converted into prompts for a segmentation foundation model such as SAM, which then predicts the segmentation. These slice-wise predictions are then fused into a final 3D output.

🧪 Interactive Inspection & Editing

In practice, both seed and grow results often require visualisation, quality checking, or manual editing, depending on your segmentation goals.

To support this, SPROUT is fully integrated into the Napari ecosystem as a plugin, please see napari-sprout.

Input Data Format

SPROUT processes 2D and 3D grayscale images stored in TIFF (.tif, .tiff) format.

  • Supported file types: .tif, .tiff
  • Image Type: 2D or 3D grayscale images
  • Bit Depth: 8-bit, 16-bit, or 32-bit (floating point)
  • File Structure:
    • 2D images: (Height, Width)
    • 3D images: (Depth, Height, Width)

Unsupported inputs: Color images.

Quickstart with Demo Data

See Demo Data and Basic Usage for a quick start.

See Scenarios for advance usage in a Q&A style.

./demo_data includes a dog skeleton dog_img.tif, a foraminifera chamber segmentation foram_img.tif and a 2D cell microscopy image 2d_cell.tif. Their corresponding seed images are also provided in the same directory.

Additional demo data can be found here.

🌰 Run seed generation

on a single image

python sprout.py --seeds --config path/to/seed_config.yaml

in batch mode

python sprout.py --seeds --batch --config path/to/batch_seed.yaml

For full details on YAML parameters and other configs see:

For example, see the YAML configuration files in ./template/.

🧠 Run Adaptive Seed Generation

on a single image

python sprout.py --adaptive_seed --config path/to/adaptive_seed_config.yaml

in batch mode

python sprout.py --adaptive_seed --batch --config path/to/batch_adaptive_seed.yaml

For full details on YAML parameters and other configs see:

For example, see the YAML configuration files in ./template/.

🌱 Run Growth

on a single image

python sprout.py --grow --config path/to/grow_config.yaml

in batch mode

python sprout.py --grow --batch --config path/to/batch_grow.yaml

For full details on YAML parameters and other configs see:

For example, see the YAML configuration files in ./template/.

🧠 SproutSAM: Run Foundation Model Prediction

on a single image or a folder of images

python sprout.py --sam --config path/to/config.yaml

in batch mode

python sprout.py --sam --batch --config path/to/batch_config.yaml

For full details on YAML parameters and other configs see:

For example, see the YAML configuration files in ./template/.

⚡ Parallelization Support

sprout.py can run tasks in parallel using Python’s threading. Just set num_threads in your config to speed up processing, especially for large datasets.

View & Edit (napari)

SPROUT also provides a napari plugin (napari-sprout): Plugins → SPROUT

From here, you can launch a set of tools to load, view, and edit your data.

  • SPROUT_main
    GUI for running seed generation, adaptive seed generation, and growth.
    Parameters match those used in the command-line scripts.

  • SPROUT_load
    Batch loader for multiple images or segmentations.

  • SPROUT_edit
    Interactive editing of segmentation results such as:

    • Click to keep or remove regions

    • Re-assign class numbers (e.g. merge i → j, delete i → 0)

    • Split disconnected regions

  • SPROUT_map
    Map regions to a semantic class scheme, e.g. 1 → bone_1, 2 → bone_2.

  • SPROUT_tools
    Miscellaneous tools, including:

    • Inspect reference shapes (e.g. show a ball of radius 10 pixels)

    • Generate batch-processing CSVs, can provide per-image adaptive thresholds (e.g. Otsu)

  • SPROUT_info
    Inspect information (e.g., resolutions, how many segmentation classes) of images or segmentations.

In addition to napari-sprout, napari also provides powerful editing options (e.g. Brush to add regions, Erase to remove).

You can also visualize, inspect, and edit seeds or results using 3D image processing tools such as 3D Slicer, DragonFly, and AVIZO. Alternatively, you can generate meshes and view or edit them in mesh-based tools like MeshLab. See Extra section

Demo Results

Batch processing results of segmenting dog bones in CT scans with varying anatomy and postures. Result1

Batch processing results of segmenting foram binary segmentation (supports segmentation masks as input too) with variable numbers of chambers Result2

Gallery of other results

Result1

Note: All results underwent manual post-processing primarily to verify and correct segmentation errors.


Extra Features

Other Optional Tools

You can use other tools to visualize and edit SPROUT's segmentation results, see Optional Tools for details.

Helper Functions

In napari-sprout and plugins, we provided GUI version of editing results. You can also find the script-version in Helper Functions.

BounTI Multithreaded Implementation

SPROUT was inspired by BounTI, a boundary-preserving threshold iteration approach:
M. Didziokas, E. Pauws, L. Kölby, R. H. Khonsari, M. Moazen. 2024.
BounTI: A user-friendly tool for automatic hard tissue segmentation. Journal of Anatomy 245, 829–841.

The script ./BounTI/run_bounti_mp.py is designed to run BounTI and BounTI Flood using a multithreaded approach. It efficiently processes a list of initial thresholds in parallel, leveraging multiple threads for improved performance.

About

Lightweight segmentation toolkit for fine-grained and multi-part segmentation of grayscale 2D/3D images, with napari support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •