Skip to main content

Neuro-SAM: Foundation Model for Dendrite and Dendritic Spine Segmentation

Project description

Neuro-SAM

Foundation Model for Dendrite and Dendritic Spine Segmentation

Neuro-SAM is a napari plugin for analysing dendritic morphology in 3D fluorescence microscopy stacks. It enables you to:

  • Trace individual dendrites in a 3D volume using waypoint-guided brightest-path search
  • Segment traced dendrites using a fine-tuned SAM2 model
  • Detect dendritic spines along each traced path
  • Segment individual spines using a dedicated fine-tuned SAM2 model

Neuro-SAM works across imaging modalities including two-photon, confocal, and STED microscopy.


๐Ÿš€ Installation

Neuro-SAM requires Python 3.10+. We recommend using Conda/Miniconda for environment management.

pip install neuro-sam

Models are downloaded automatically on first use and stored in src/neuro_sam/checkpoints/ โ€” easy to find and delete.

To pre-download all models and the sample dataset:

neuro-sam-download

GPU acceleration is supported via CUDA and MPS (Apple Silicon).


๐Ÿ“Š Usage

# Launch with the built-in benchmark dataset
neuro-sam

# Launch with your own dataset
neuro-sam --image-path /path/to/your/image.tif

๐Ÿ—ƒ Repository Structure

src/neuro_sam/
โ”œโ”€โ”€ checkpoints/          # model weights (auto-downloaded on first use)
โ”œโ”€โ”€ napari_utils/         # UI widgets and inference modules
โ”‚   โ”œโ”€โ”€ main_widget.py          # top-level plugin widget
โ”‚   โ”œโ”€โ”€ path_tracing_module.py  # waypoint path tracing
โ”‚   โ”œโ”€โ”€ segmentation_module.py  # dendrite segmentation
โ”‚   โ”œโ”€โ”€ segmentation_model.py   # SAM2 dendrite model wrapper
โ”‚   โ”œโ”€โ”€ spine_detection_module.py     # spine detection
โ”‚   โ”œโ”€โ”€ spine_segmentation_module.py  # spine segmentation UI
โ”‚   โ”œโ”€โ”€ spine_segmentation_model.py   # SAM2 spine model wrapper
โ”‚   โ””โ”€โ”€ anisotropic_scaling.py  # voxel spacing / scaling
โ”œโ”€โ”€ brightest_path_lib/   # waypoint A* path tracing algorithm
โ”œโ”€โ”€ training/             # training scripts for fine-tuning
โ”œโ”€โ”€ plugin.py             # napari entry point
โ””โ”€โ”€ utils.py              # model download and shared utilities

๐Ÿ”ฌ Workflow

1. Configure Voxel Spacing

In the Path Tracing tab, set accurate X, Y, Z voxel spacing (nm) for your acquisition. This ensures correct anisotropic scaling throughout the pipeline.

2. Trace Dendritic Paths

  • Click waypoints along dendrite structures in the viewer
  • Use Load Dataset to switch datasets without restarting
  • The algorithm finds the optimal brightest path between waypoints

3. Segment Dendrites

  • Go to the Segmentation tab
  • Load the pre-trained SAM2 dendrite model
  • Run segmentation on individual traced paths

4. Detect Spines

  • Go to the Spine Detection tab
  • Select a segmented path
  • Run automatic spine detection using tubular view analysis

5. Segment Spines

  • Go to the Spine Segmentation tab
  • Load the pre-trained SAM2 spine model
  • Run spine segmentation on detected spine positions
  • Export spine masks as TIFF files

๐Ÿ—‚ Models

Model Description
sam2.1_hiera_small.pt SAM2 base checkpoint
dendrite_model.torch Fine-tuned weights for dendrite segmentation
spine_model.torch Fine-tuned weights for spine segmentation

All models are downloaded from the GitHub release on first use.


๐Ÿ“ฌ Contact

Made with โ™ฅ๏ธ at Anki Lab ๐Ÿง โœจ

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

neuro_sam-0.1.18.tar.gz (199.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuro_sam-0.1.18-py3-none-any.whl (255.0 kB view details)

Uploaded Python 3

File details

Details for the file neuro_sam-0.1.18.tar.gz.

File metadata

  • Download URL: neuro_sam-0.1.18.tar.gz
  • Upload date:
  • Size: 199.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for neuro_sam-0.1.18.tar.gz
Algorithm Hash digest
SHA256 019aec0a6bdfa85f50ebb43cfdd18bd67b9bf910d4a0e13bfec66d40391901e9
MD5 fc6c2bc65702543dc5cdbe1f5a20c3eb
BLAKE2b-256 a7d68c5e5b53418eded66ba5825184e3cdc027e7f134839eeb7050ed737699bb

See more details on using hashes here.

File details

Details for the file neuro_sam-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: neuro_sam-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 255.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for neuro_sam-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 3dfb186345cf54bd8e0414e7d2f697dec154d95738a60ebee1f4856b67b3467a
MD5 a470f45e6233c1e1171509464f67c93f
BLAKE2b-256 66aeaf531eb71ca84eaa088cdf47845250ed5f604cc6158e6e62dd2f7a652ea8

See more details on using hashes here.

Supported by

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