neuro-sam 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- neuro_sam-0.1.0/LICENSE +21 -0
- neuro_sam-0.1.0/PKG-INFO +269 -0
- neuro_sam-0.1.0/README.md +215 -0
- neuro_sam-0.1.0/pyproject.toml +56 -0
- neuro_sam-0.1.0/setup.cfg +4 -0
- neuro_sam-0.1.0/src/neuro_sam/__init__.py +1 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/__init__.py +5 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/algorithm/__init__.py +3 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/algorithm/astar.py +586 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/algorithm/waypointastar.py +449 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/algorithm/waypointastar_speedup.py +1007 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/connected_componen.py +329 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/cost/__init__.py +8 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/cost/cost.py +33 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/cost/reciprocal.py +90 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/cost/reciprocal_transonic.py +86 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/heuristic/__init__.py +2 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/heuristic/euclidean.py +101 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/heuristic/heuristic.py +29 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/image/__init__.py +1 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/image/stats.py +197 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/input/__init__.py +1 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/input/inputs.py +14 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/node/__init__.py +2 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/node/bidirectional_node.py +240 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/node/node.py +125 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/visualization/__init__.py +4 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/visualization/flythrough.py +133 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/visualization/flythrough_all.py +394 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/visualization/tube_data.py +385 -0
- neuro_sam-0.1.0/src/neuro_sam/brightest_path_lib/visualization/tube_flythrough.py +227 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/anisotropic_scaling.py +503 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/color_utils.py +135 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/contrasting_color_system.py +169 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/main_widget.py +1016 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/path_tracing_module.py +1016 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/punet_widget.py +424 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/segmentation_model.py +769 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/segmentation_module.py +649 -0
- neuro_sam-0.1.0/src/neuro_sam/napari_utils/visualization_module.py +574 -0
- neuro_sam-0.1.0/src/neuro_sam/plugin.py +260 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/__init__.py +0 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/deepd3_model.py +231 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/prob_unet_deepd3.py +431 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/prob_unet_with_tversky.py +375 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/punet_inference.py +236 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/run_inference.py +145 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/unet_blocks.py +81 -0
- neuro_sam-0.1.0/src/neuro_sam/punet/utils.py +52 -0
- neuro_sam-0.1.0/src/neuro_sam.egg-info/PKG-INFO +269 -0
- neuro_sam-0.1.0/src/neuro_sam.egg-info/SOURCES.txt +96 -0
- neuro_sam-0.1.0/src/neuro_sam.egg-info/dependency_links.txt +1 -0
- neuro_sam-0.1.0/src/neuro_sam.egg-info/entry_points.txt +2 -0
- neuro_sam-0.1.0/src/neuro_sam.egg-info/requires.txt +16 -0
- neuro_sam-0.1.0/src/neuro_sam.egg-info/top_level.txt +2 -0
- neuro_sam-0.1.0/src/sam2/__init__.py +11 -0
- neuro_sam-0.1.0/src/sam2/automatic_mask_generator.py +454 -0
- neuro_sam-0.1.0/src/sam2/benchmark.py +92 -0
- neuro_sam-0.1.0/src/sam2/build_sam.py +174 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2/sam2_hiera_b+.yaml +113 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2/sam2_hiera_l.yaml +117 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2/sam2_hiera_s.yaml +116 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2/sam2_hiera_t.yaml +118 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2.1/sam2.1_hiera_b+.yaml +116 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2.1/sam2.1_hiera_l.yaml +120 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2.1/sam2.1_hiera_s.yaml +119 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2.1/sam2.1_hiera_t.yaml +121 -0
- neuro_sam-0.1.0/src/sam2/configs/sam2.1_training/sam2.1_hiera_b+_MOSE_finetune.yaml +339 -0
- neuro_sam-0.1.0/src/sam2/configs/train.yaml +335 -0
- neuro_sam-0.1.0/src/sam2/modeling/__init__.py +5 -0
- neuro_sam-0.1.0/src/sam2/modeling/backbones/__init__.py +5 -0
- neuro_sam-0.1.0/src/sam2/modeling/backbones/hieradet.py +317 -0
- neuro_sam-0.1.0/src/sam2/modeling/backbones/image_encoder.py +134 -0
- neuro_sam-0.1.0/src/sam2/modeling/backbones/utils.py +93 -0
- neuro_sam-0.1.0/src/sam2/modeling/memory_attention.py +169 -0
- neuro_sam-0.1.0/src/sam2/modeling/memory_encoder.py +181 -0
- neuro_sam-0.1.0/src/sam2/modeling/position_encoding.py +239 -0
- neuro_sam-0.1.0/src/sam2/modeling/sam/__init__.py +5 -0
- neuro_sam-0.1.0/src/sam2/modeling/sam/mask_decoder.py +295 -0
- neuro_sam-0.1.0/src/sam2/modeling/sam/prompt_encoder.py +202 -0
- neuro_sam-0.1.0/src/sam2/modeling/sam/transformer.py +311 -0
- neuro_sam-0.1.0/src/sam2/modeling/sam2_base.py +911 -0
- neuro_sam-0.1.0/src/sam2/modeling/sam2_utils.py +323 -0
- neuro_sam-0.1.0/src/sam2/sam2.1_hiera_b+.yaml +116 -0
- neuro_sam-0.1.0/src/sam2/sam2.1_hiera_l.yaml +120 -0
- neuro_sam-0.1.0/src/sam2/sam2.1_hiera_s.yaml +119 -0
- neuro_sam-0.1.0/src/sam2/sam2.1_hiera_t.yaml +121 -0
- neuro_sam-0.1.0/src/sam2/sam2_hiera_b+.yaml +113 -0
- neuro_sam-0.1.0/src/sam2/sam2_hiera_l.yaml +117 -0
- neuro_sam-0.1.0/src/sam2/sam2_hiera_s.yaml +116 -0
- neuro_sam-0.1.0/src/sam2/sam2_hiera_t.yaml +118 -0
- neuro_sam-0.1.0/src/sam2/sam2_image_predictor.py +475 -0
- neuro_sam-0.1.0/src/sam2/sam2_video_predictor.py +1222 -0
- neuro_sam-0.1.0/src/sam2/sam2_video_predictor_legacy.py +1172 -0
- neuro_sam-0.1.0/src/sam2/utils/__init__.py +5 -0
- neuro_sam-0.1.0/src/sam2/utils/amg.py +348 -0
- neuro_sam-0.1.0/src/sam2/utils/misc.py +349 -0
- neuro_sam-0.1.0/src/sam2/utils/transforms.py +118 -0
neuro_sam-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nipun Arora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
neuro_sam-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neuro-sam
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Neuro-SAM: Foundation Models for Dendrite and Dendritic Spine Segmentation
|
|
5
|
+
Author-email: Nipun Arora <nipun.arora@fau.de>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Nipun Arora
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/nipunarora8/Neuro-SAM
|
|
29
|
+
Project-URL: Bug Tracker, https://github.com/nipunarora8/Neuro-SAM/issues
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Classifier: Framework :: napari
|
|
34
|
+
Requires-Python: >=3.10
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE
|
|
37
|
+
Requires-Dist: napari
|
|
38
|
+
Requires-Dist: numpy
|
|
39
|
+
Requires-Dist: scipy
|
|
40
|
+
Requires-Dist: imageio
|
|
41
|
+
Requires-Dist: torch>=2.0.0
|
|
42
|
+
Requires-Dist: torchvision>=0.15.0
|
|
43
|
+
Requires-Dist: hydra-core>=1.3.2
|
|
44
|
+
Requires-Dist: iopath>=0.1.10
|
|
45
|
+
Requires-Dist: pillow>=9.4.0
|
|
46
|
+
Requires-Dist: tqdm>=4.66.1
|
|
47
|
+
Requires-Dist: vispy
|
|
48
|
+
Requires-Dist: qtpy
|
|
49
|
+
Requires-Dist: superqt
|
|
50
|
+
Requires-Dist: magicgui
|
|
51
|
+
Requires-Dist: scikit-image
|
|
52
|
+
Requires-Dist: tifffile
|
|
53
|
+
Dynamic: license-file
|
|
54
|
+
|
|
55
|
+
<div align="center">
|
|
56
|
+
|
|
57
|
+
# Neuro-SAM
|
|
58
|
+
#### Foundation Models from Dendrite and Dendritic Spine Segmentation
|
|
59
|
+
|
|
60
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
61
|
+
[](https://pytorch.org/get-started/locally/)
|
|
62
|
+
[](https://wandb.ai/site)
|
|
63
|
+
|
|
64
|
+
This project demonstrates an interactive UI to segment dendrites and dendritic spines.
|
|
65
|
+
The model of choice is SAMv2 and the framework used is pytorch.
|
|
66
|
+
|
|
67
|
+

|
|
68
|
+
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
### š Table of Contents
|
|
72
|
+
|
|
73
|
+
- [Neuro-SAM](#neuro-sam)
|
|
74
|
+
- [š Table of Contents](#--table-of-contents)
|
|
75
|
+
- [š§ Overview](#-overview)
|
|
76
|
+
- [š¦ Built With](#-built-with)
|
|
77
|
+
- [š Repository Structure](#-repository-structure)
|
|
78
|
+
- [š Installation](#-installation)
|
|
79
|
+
- [š Usage](#-usage)
|
|
80
|
+
- [š Workflow](#-workflow)
|
|
81
|
+
- [š§āš» Model Training](#-model-training)
|
|
82
|
+
- [š Data Format](#-data-format)
|
|
83
|
+
- [š License](#-license)
|
|
84
|
+
- [š¬ Contact](#-contact)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### š§ Overview
|
|
88
|
+
|
|
89
|
+
Neuro-SAM provides an end-to-end pipeline for analyzing neural structures from 3D microscopy data, featuring:
|
|
90
|
+
|
|
91
|
+
- **Path Tracing**: Waypoint-based A* pathfinding
|
|
92
|
+
- **Dendrite Segmentation**: SAM2-based dendrite segmentation
|
|
93
|
+
- **Smart Spine Detection**: Multi-view analysis for spine detection
|
|
94
|
+
- **Spine Segmentation**: Individual spine segmentation using trained SAM2 model
|
|
95
|
+
|
|
96
|
+
### š¦ Built With
|
|
97
|
+
|
|
98
|
+
[PyTorch](https://pytorch.org) - an open-source machine learning library for Python, widely used for deep learning applications.
|
|
99
|
+
|
|
100
|
+
[Segment Anything Model](https://segment-anything.com) - a foundation model used for segmentation built by Meta AI.
|
|
101
|
+
|
|
102
|
+
[Weights and Biases](https://wandb.ai/site) - a tool for tracking and visualizing machine learning experiments.
|
|
103
|
+
|
|
104
|
+
[Visual Studio Code](https://code.visualstudio.com/) - a code editor redefined and optimized for building applications.
|
|
105
|
+
|
|
106
|
+
[FAU High Performance Computing](https://doc.nhr.fau.de/) - a high-performance computing cluster at Friedrich-Alexander-Universität Erlangen-Nürnberg.
|
|
107
|
+
|
|
108
|
+
### š Repository Structure
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
Neuro-SAM/
|
|
112
|
+
āāā Train-SAMv2/ # SAM2 training infrastructure
|
|
113
|
+
ā āāā sam2/ # SAM2 model implementation
|
|
114
|
+
ā āāā checkpoints/ # Model checkpoints
|
|
115
|
+
ā āāā results/ # Trained model outputs
|
|
116
|
+
ā āāā utils/ # Training utilities
|
|
117
|
+
ā āāā train_dendrites.py # Dendrite model training
|
|
118
|
+
ā āāā train_spines.py # Spine model training
|
|
119
|
+
āāā brightest_path_lib/ # Advanced pathfinding algorithms
|
|
120
|
+
ā āāā algorithm/ # A* and waypoint search implementations
|
|
121
|
+
ā āāā cost/ # Cost function definitions
|
|
122
|
+
ā āāā heuristic/ # Heuristic functions
|
|
123
|
+
ā āāā visualization/ # Path visualization tools
|
|
124
|
+
ā āāā ...
|
|
125
|
+
āāā napari_utils/ # Napari plugin components
|
|
126
|
+
ā āāā main_widget.py # Main interface with anisotropic scaling
|
|
127
|
+
ā āāā path_tracing_module.py # Interactive path tracing
|
|
128
|
+
ā āāā segmentation_module.py # Dendrite segmentation interface
|
|
129
|
+
ā āāā spine_detection_module.py # Spine detection with smart tracking
|
|
130
|
+
ā āāā spine_segmentation_module.py # Individual spine segmentation
|
|
131
|
+
ā āāā visualization_module.py # Path management and visualization
|
|
132
|
+
āāā neuro_sam_plugin.py # Main plugin entry point
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### š Installation
|
|
136
|
+
|
|
137
|
+
#### Prerequisites
|
|
138
|
+
|
|
139
|
+
- Python 3.10+
|
|
140
|
+
- CUDA-compatible GPU (recommended)
|
|
141
|
+
- Conda/Miniconda
|
|
142
|
+
|
|
143
|
+
#### Environment Setup
|
|
144
|
+
|
|
145
|
+
1. **Clone the repository:**
|
|
146
|
+
```bash
|
|
147
|
+
git clone https://github.com/nipunarora8/Neuro-SAM.git
|
|
148
|
+
cd Neuro-SAM
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
2. **Create local environment:**
|
|
152
|
+
```bash
|
|
153
|
+
conda create -p ./.venv python=3.10 -c conda-forge
|
|
154
|
+
conda activate ./.venv
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
3. **Install dependencies:**
|
|
158
|
+
```bash
|
|
159
|
+
pip install uv
|
|
160
|
+
uv sync
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
4. **Download SAM2 checkpoints:**
|
|
164
|
+
```bash
|
|
165
|
+
cd Train-SAMv2/checkpoints
|
|
166
|
+
bash download_ckpts.sh
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### š Usage
|
|
170
|
+
|
|
171
|
+
#### Quick Start
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from neuro_sam_plugin import run_neuro_sam
|
|
175
|
+
|
|
176
|
+
# Launch with default spacing (94nm x 94nm x 500nm)
|
|
177
|
+
viewer = run_neuro_sam(image_path="your_image.tif")
|
|
178
|
+
|
|
179
|
+
# Launch with custom voxel spacing
|
|
180
|
+
viewer = run_neuro_sam(
|
|
181
|
+
image_path="your_image.tif",
|
|
182
|
+
spacing_xyz=(100.0, 100.0, 300.0) # X, Y, Z spacing in nm
|
|
183
|
+
)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Command Line Interface
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Basic usage
|
|
190
|
+
python neuro_sam_plugin.py --image_path /path/to/your/image.tif
|
|
191
|
+
|
|
192
|
+
# Custom spacing
|
|
193
|
+
python neuro_sam_plugin.py --image_path image.tif \
|
|
194
|
+
--x-spacing 100.0 --y-spacing 100.0 --z-spacing 300.0
|
|
195
|
+
|
|
196
|
+
# Load benchmark dataset
|
|
197
|
+
python neuro_sam_plugin.py
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### š¬ Workflow
|
|
201
|
+
|
|
202
|
+
#### 1. **Configure Voxel Spacing**
|
|
203
|
+
Set accurate X, Y, Z voxel spacing in the "Path Tracing" tab for proper anisotropic scaling:
|
|
204
|
+
- Typical two-photon: 94nm Ć 94nm Ć 500nm
|
|
205
|
+
- Confocal: varies by objective and zoom
|
|
206
|
+
|
|
207
|
+
#### 2. **Trace Dendritic Paths**
|
|
208
|
+
- Click waypoints along dendrite structures
|
|
209
|
+
- Algorithm automatically finds optimal brightess paths
|
|
210
|
+
|
|
211
|
+
#### 3. **Segment Dendrites**
|
|
212
|
+
- Load pre-trained SAMv2 dendrite model
|
|
213
|
+
- Segment individual path with SAMv2
|
|
214
|
+
|
|
215
|
+
#### 4. **Detect Spines**
|
|
216
|
+
- Smart multi-view detection using tube data generation
|
|
217
|
+
- Angle-based matching between 2D and tubular views
|
|
218
|
+
|
|
219
|
+
#### 5. **Segment Spines**
|
|
220
|
+
- Fine-grained spine segmentation using specialized SAMv2 model
|
|
221
|
+
- Dendrite mask overlay to suppress background signal
|
|
222
|
+
- Manual point extension across frames
|
|
223
|
+
- Contrasting color system for visualization
|
|
224
|
+
|
|
225
|
+
### š§ Model Training
|
|
226
|
+
|
|
227
|
+
#### Dendrite Model
|
|
228
|
+
```bash
|
|
229
|
+
cd Train-SAMv2
|
|
230
|
+
python train_dendrites.py --ppn 20 --pnn 10 --batch_size 32 --model_name "small"
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Spine Model
|
|
234
|
+
```bash
|
|
235
|
+
python train_spines.py --model_name "small" --batch_size 16
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### š Data Format
|
|
239
|
+
|
|
240
|
+
#### Input Requirements
|
|
241
|
+
- **Image Format**: TIFF, .d3set (to reproduce training results)
|
|
242
|
+
- **Dimensions**: 3D volumes (ZĆYĆX)
|
|
243
|
+
- **Bit Depth**: 8-bit or 16-bit grayscale
|
|
244
|
+
- **Size**: Tested up to 2048Ć2048Ć500 voxels
|
|
245
|
+
|
|
246
|
+
#### Output Formats
|
|
247
|
+
- **Paths**: NumPy arrays with coordinates
|
|
248
|
+
- **Masks**: Binary TIFF volumes
|
|
249
|
+
|
|
250
|
+
### š License
|
|
251
|
+
|
|
252
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
#### Useful VSCode Extensions
|
|
256
|
+
|
|
257
|
+
- [Remote Explorer](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-explorer) - Open projects on remote servers.
|
|
258
|
+
- [Log Viewer](https://marketplace.visualstudio.com/items?itemName=berublan.vscode-log-viewer) - A log monitoring extension.
|
|
259
|
+
- [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) - Python auto code formatter.
|
|
260
|
+
- [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) - Markdown preview and editing.
|
|
261
|
+
|
|
262
|
+
### š¬ Contact
|
|
263
|
+
|
|
264
|
+
Nipun Arora - nipun.arora@fau.de
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
<div align="center">
|
|
268
|
+
<b>Made with ā„ļø at Anki Lab š§ āØ</b>
|
|
269
|
+
</div>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Neuro-SAM
|
|
4
|
+
#### Foundation Models from Dendrite and Dendritic Spine Segmentation
|
|
5
|
+
|
|
6
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
7
|
+
[](https://pytorch.org/get-started/locally/)
|
|
8
|
+
[](https://wandb.ai/site)
|
|
9
|
+
|
|
10
|
+
This project demonstrates an interactive UI to segment dendrites and dendritic spines.
|
|
11
|
+
The model of choice is SAMv2 and the framework used is pytorch.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
### š Table of Contents
|
|
18
|
+
|
|
19
|
+
- [Neuro-SAM](#neuro-sam)
|
|
20
|
+
- [š Table of Contents](#--table-of-contents)
|
|
21
|
+
- [š§ Overview](#-overview)
|
|
22
|
+
- [š¦ Built With](#-built-with)
|
|
23
|
+
- [š Repository Structure](#-repository-structure)
|
|
24
|
+
- [š Installation](#-installation)
|
|
25
|
+
- [š Usage](#-usage)
|
|
26
|
+
- [š Workflow](#-workflow)
|
|
27
|
+
- [š§āš» Model Training](#-model-training)
|
|
28
|
+
- [š Data Format](#-data-format)
|
|
29
|
+
- [š License](#-license)
|
|
30
|
+
- [š¬ Contact](#-contact)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### š§ Overview
|
|
34
|
+
|
|
35
|
+
Neuro-SAM provides an end-to-end pipeline for analyzing neural structures from 3D microscopy data, featuring:
|
|
36
|
+
|
|
37
|
+
- **Path Tracing**: Waypoint-based A* pathfinding
|
|
38
|
+
- **Dendrite Segmentation**: SAM2-based dendrite segmentation
|
|
39
|
+
- **Smart Spine Detection**: Multi-view analysis for spine detection
|
|
40
|
+
- **Spine Segmentation**: Individual spine segmentation using trained SAM2 model
|
|
41
|
+
|
|
42
|
+
### š¦ Built With
|
|
43
|
+
|
|
44
|
+
[PyTorch](https://pytorch.org) - an open-source machine learning library for Python, widely used for deep learning applications.
|
|
45
|
+
|
|
46
|
+
[Segment Anything Model](https://segment-anything.com) - a foundation model used for segmentation built by Meta AI.
|
|
47
|
+
|
|
48
|
+
[Weights and Biases](https://wandb.ai/site) - a tool for tracking and visualizing machine learning experiments.
|
|
49
|
+
|
|
50
|
+
[Visual Studio Code](https://code.visualstudio.com/) - a code editor redefined and optimized for building applications.
|
|
51
|
+
|
|
52
|
+
[FAU High Performance Computing](https://doc.nhr.fau.de/) - a high-performance computing cluster at Friedrich-Alexander-Universität Erlangen-Nürnberg.
|
|
53
|
+
|
|
54
|
+
### š Repository Structure
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
Neuro-SAM/
|
|
58
|
+
āāā Train-SAMv2/ # SAM2 training infrastructure
|
|
59
|
+
ā āāā sam2/ # SAM2 model implementation
|
|
60
|
+
ā āāā checkpoints/ # Model checkpoints
|
|
61
|
+
ā āāā results/ # Trained model outputs
|
|
62
|
+
ā āāā utils/ # Training utilities
|
|
63
|
+
ā āāā train_dendrites.py # Dendrite model training
|
|
64
|
+
ā āāā train_spines.py # Spine model training
|
|
65
|
+
āāā brightest_path_lib/ # Advanced pathfinding algorithms
|
|
66
|
+
ā āāā algorithm/ # A* and waypoint search implementations
|
|
67
|
+
ā āāā cost/ # Cost function definitions
|
|
68
|
+
ā āāā heuristic/ # Heuristic functions
|
|
69
|
+
ā āāā visualization/ # Path visualization tools
|
|
70
|
+
ā āāā ...
|
|
71
|
+
āāā napari_utils/ # Napari plugin components
|
|
72
|
+
ā āāā main_widget.py # Main interface with anisotropic scaling
|
|
73
|
+
ā āāā path_tracing_module.py # Interactive path tracing
|
|
74
|
+
ā āāā segmentation_module.py # Dendrite segmentation interface
|
|
75
|
+
ā āāā spine_detection_module.py # Spine detection with smart tracking
|
|
76
|
+
ā āāā spine_segmentation_module.py # Individual spine segmentation
|
|
77
|
+
ā āāā visualization_module.py # Path management and visualization
|
|
78
|
+
āāā neuro_sam_plugin.py # Main plugin entry point
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### š Installation
|
|
82
|
+
|
|
83
|
+
#### Prerequisites
|
|
84
|
+
|
|
85
|
+
- Python 3.10+
|
|
86
|
+
- CUDA-compatible GPU (recommended)
|
|
87
|
+
- Conda/Miniconda
|
|
88
|
+
|
|
89
|
+
#### Environment Setup
|
|
90
|
+
|
|
91
|
+
1. **Clone the repository:**
|
|
92
|
+
```bash
|
|
93
|
+
git clone https://github.com/nipunarora8/Neuro-SAM.git
|
|
94
|
+
cd Neuro-SAM
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
2. **Create local environment:**
|
|
98
|
+
```bash
|
|
99
|
+
conda create -p ./.venv python=3.10 -c conda-forge
|
|
100
|
+
conda activate ./.venv
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
3. **Install dependencies:**
|
|
104
|
+
```bash
|
|
105
|
+
pip install uv
|
|
106
|
+
uv sync
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
4. **Download SAM2 checkpoints:**
|
|
110
|
+
```bash
|
|
111
|
+
cd Train-SAMv2/checkpoints
|
|
112
|
+
bash download_ckpts.sh
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### š Usage
|
|
116
|
+
|
|
117
|
+
#### Quick Start
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from neuro_sam_plugin import run_neuro_sam
|
|
121
|
+
|
|
122
|
+
# Launch with default spacing (94nm x 94nm x 500nm)
|
|
123
|
+
viewer = run_neuro_sam(image_path="your_image.tif")
|
|
124
|
+
|
|
125
|
+
# Launch with custom voxel spacing
|
|
126
|
+
viewer = run_neuro_sam(
|
|
127
|
+
image_path="your_image.tif",
|
|
128
|
+
spacing_xyz=(100.0, 100.0, 300.0) # X, Y, Z spacing in nm
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### Command Line Interface
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Basic usage
|
|
136
|
+
python neuro_sam_plugin.py --image_path /path/to/your/image.tif
|
|
137
|
+
|
|
138
|
+
# Custom spacing
|
|
139
|
+
python neuro_sam_plugin.py --image_path image.tif \
|
|
140
|
+
--x-spacing 100.0 --y-spacing 100.0 --z-spacing 300.0
|
|
141
|
+
|
|
142
|
+
# Load benchmark dataset
|
|
143
|
+
python neuro_sam_plugin.py
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### š¬ Workflow
|
|
147
|
+
|
|
148
|
+
#### 1. **Configure Voxel Spacing**
|
|
149
|
+
Set accurate X, Y, Z voxel spacing in the "Path Tracing" tab for proper anisotropic scaling:
|
|
150
|
+
- Typical two-photon: 94nm Ć 94nm Ć 500nm
|
|
151
|
+
- Confocal: varies by objective and zoom
|
|
152
|
+
|
|
153
|
+
#### 2. **Trace Dendritic Paths**
|
|
154
|
+
- Click waypoints along dendrite structures
|
|
155
|
+
- Algorithm automatically finds optimal brightess paths
|
|
156
|
+
|
|
157
|
+
#### 3. **Segment Dendrites**
|
|
158
|
+
- Load pre-trained SAMv2 dendrite model
|
|
159
|
+
- Segment individual path with SAMv2
|
|
160
|
+
|
|
161
|
+
#### 4. **Detect Spines**
|
|
162
|
+
- Smart multi-view detection using tube data generation
|
|
163
|
+
- Angle-based matching between 2D and tubular views
|
|
164
|
+
|
|
165
|
+
#### 5. **Segment Spines**
|
|
166
|
+
- Fine-grained spine segmentation using specialized SAMv2 model
|
|
167
|
+
- Dendrite mask overlay to suppress background signal
|
|
168
|
+
- Manual point extension across frames
|
|
169
|
+
- Contrasting color system for visualization
|
|
170
|
+
|
|
171
|
+
### š§ Model Training
|
|
172
|
+
|
|
173
|
+
#### Dendrite Model
|
|
174
|
+
```bash
|
|
175
|
+
cd Train-SAMv2
|
|
176
|
+
python train_dendrites.py --ppn 20 --pnn 10 --batch_size 32 --model_name "small"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Spine Model
|
|
180
|
+
```bash
|
|
181
|
+
python train_spines.py --model_name "small" --batch_size 16
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### š Data Format
|
|
185
|
+
|
|
186
|
+
#### Input Requirements
|
|
187
|
+
- **Image Format**: TIFF, .d3set (to reproduce training results)
|
|
188
|
+
- **Dimensions**: 3D volumes (ZĆYĆX)
|
|
189
|
+
- **Bit Depth**: 8-bit or 16-bit grayscale
|
|
190
|
+
- **Size**: Tested up to 2048Ć2048Ć500 voxels
|
|
191
|
+
|
|
192
|
+
#### Output Formats
|
|
193
|
+
- **Paths**: NumPy arrays with coordinates
|
|
194
|
+
- **Masks**: Binary TIFF volumes
|
|
195
|
+
|
|
196
|
+
### š License
|
|
197
|
+
|
|
198
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
#### Useful VSCode Extensions
|
|
202
|
+
|
|
203
|
+
- [Remote Explorer](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-explorer) - Open projects on remote servers.
|
|
204
|
+
- [Log Viewer](https://marketplace.visualstudio.com/items?itemName=berublan.vscode-log-viewer) - A log monitoring extension.
|
|
205
|
+
- [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) - Python auto code formatter.
|
|
206
|
+
- [Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) - Markdown preview and editing.
|
|
207
|
+
|
|
208
|
+
### š¬ Contact
|
|
209
|
+
|
|
210
|
+
Nipun Arora - nipun.arora@fau.de
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
<div align="center">
|
|
214
|
+
<b>Made with ā„ļø at Anki Lab š§ āØ</b>
|
|
215
|
+
</div>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "neuro-sam"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Neuro-SAM: Foundation Models for Dendrite and Dendritic Spine Segmentation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Nipun Arora", email = "nipun.arora@fau.de" },
|
|
12
|
+
]
|
|
13
|
+
license = { file = "LICENSE" }
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Framework :: napari",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"napari",
|
|
22
|
+
"numpy",
|
|
23
|
+
"scipy",
|
|
24
|
+
"imageio",
|
|
25
|
+
"torch>=2.0.0",
|
|
26
|
+
"torchvision>=0.15.0",
|
|
27
|
+
"hydra-core>=1.3.2",
|
|
28
|
+
"iopath>=0.1.10",
|
|
29
|
+
"pillow>=9.4.0",
|
|
30
|
+
"tqdm>=4.66.1",
|
|
31
|
+
"vispy",
|
|
32
|
+
"qtpy",
|
|
33
|
+
"superqt",
|
|
34
|
+
"magicgui",
|
|
35
|
+
"scikit-image",
|
|
36
|
+
"tifffile"
|
|
37
|
+
]
|
|
38
|
+
requires-python = ">=3.10"
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
"Homepage" = "https://github.com/nipunarora8/Neuro-SAM"
|
|
42
|
+
"Bug Tracker" = "https://github.com/nipunarora8/Neuro-SAM/issues"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
|
46
|
+
include = ["neuro_sam*", "sam2*"]
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.package-data]
|
|
49
|
+
"sam2" = ["*.yaml", "configs/**/*.yaml"]
|
|
50
|
+
"neuro_sam" = ["napari.yaml"]
|
|
51
|
+
|
|
52
|
+
[project.entry-points."napari.manifest"]
|
|
53
|
+
neuro-sam = "neuro_sam:napari.yaml"
|
|
54
|
+
|
|
55
|
+
[tool.uv]
|
|
56
|
+
package = true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .plugin import run_neuro_sam
|