Skip to content

ankilab/Neuro-SAM

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 🧠✨

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 99.1%
  • Cuda 0.9%