Skip to content

Commit 26af401

Browse files
committed
Documentation for Spiner2D
1 parent d3fbeb0 commit 26af401

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

scripts/baselines/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Other networks/methods have been evaluated on SGN and IHC crops to compare the proposed method to the state of the art and justify the development of said method.
44
Cellpose 3, Cellpose-SAM, micro-sam, and the distance U-Net were evaluated for both SGNs and IHCs.
5-
Additionally, Stardist was used for SGN segmentation.
5+
Additionally, Stardist and Spiner (2D) were used for the SGN segmentation.
66
HCAT, a specialized tool for the segmentation of IHCs, was omitted because it is a purely 2D network and, therefore, does not fit the use case.
77

88
## Micro-sam
@@ -19,7 +19,7 @@ python -m pip install cellpose
1919
python -m pip install cellpose --upgrade
2020
```
2121

22-
The script is adaapted from the [example Jupyter notebook online](https://github.com/MouseLand/cellpose/blob/main/notebooks/run_Cellpose-SAM.ipynb).
22+
The script is adapted from the [example Jupyter notebook online](https://github.com/MouseLand/cellpose/blob/main/notebooks/run_Cellpose-SAM.ipynb).
2323

2424
## Cellpose 3
2525

@@ -32,6 +32,12 @@ python -m pip install cellpose==3.1.1.2
3232

3333
The script is adapted from the [example Jupyter notebook online](https://github.com/MouseLand/cellpose/blob/main/notebooks/run_cellpose3.ipynb).
3434

35+
## Spiner
36+
37+
The installation follows the instructions in the [Github repository](https://github.com/reubenrosenNCSU/cellannotation).
38+
It is the 2D implementation of Spiner: **Sp**iral gangl**i**on **n**euron profil**er**
39+
DOI: 10.1016/j.isci.2025.112929
40+
3541
## Stardist
3642

3743
Installation:

scripts/baselines/eval_baseline.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def eval_all_sgn():
6262
baselines = [
6363
"spiner2D",
6464
"cellpose3",
65-
"cellpose-sam_2025-10",
65+
"cellpose-sam",
6666
"distance_unet",
6767
"micro-sam",
6868
"stardist",
@@ -84,7 +84,7 @@ def eval_all_ihc():
8484
annotation_dir = os.path.join(cochlea_dir, "AnnotatedImageCrops/F1ValidationIHCs/consensus_annotation")
8585
baselines = [
8686
"cellpose3",
87-
# "cellpose-sam_2025-11",
87+
"cellpose-sam",
8888
"distance_unet_v4b",
8989
"micro-sam",
9090
]
@@ -94,6 +94,13 @@ def eval_all_ihc():
9494

9595

9696
def eval_segmentation(seg_dir, annotation_dir, filter=True):
97+
"""Evaluate 3D segmentation from baseline methods.
98+
99+
Args:
100+
seg_dir: Directory containing segmentation output of baseline methods.
101+
annotation_dir: Directory containing annotations in CSV format.
102+
filter: Bool for filtering segmentation based on size. Per default size between 3000 and 50000 pixels.
103+
"""
97104
print(f"Evaluating segmentation in directory {seg_dir}")
98105
segs = [entry.path for entry in os.scandir(seg_dir) if entry.is_file() and ".tif" in entry.path]
99106

@@ -141,6 +148,15 @@ def eval_segmentation(seg_dir, annotation_dir, filter=True):
141148

142149

143150
def eval_segmentation_spiner(seg_dir, annotation_dir):
151+
"""Evaluate 2D spiner segmentation: https://github.com/reubenrosenNCSU/cellannotation
152+
The segmentation tool, which is used inside a browser, exports bounding boxes in the CSV format.
153+
An instance segmentation is created based on the CSV data and used for evaluation.
154+
The size filter is left out because the segmentation is only 2D and has limited sizes per default.
155+
156+
Args:
157+
seg_dir: Directory containing segmentation output of baseline methods.
158+
annotation_dir: Directory containing annotations in CSV format.
159+
"""
144160
print(f"Evaluating segmentation in directory {seg_dir}")
145161
annots = [entry.path for entry in os.scandir(seg_dir)
146162
if entry.is_file() and ".csv" in entry.path]
@@ -163,6 +179,7 @@ def eval_segmentation_spiner(seg_dir, annotation_dir):
163179

164180
df_annot = pd.read_csv(annot, sep=",")
165181
for num, row in df_annot.iterrows():
182+
# coordinate switch to account for image orientation in Python
166183
x1 = int(row["y1"])
167184
x2 = int(row["y2"])
168185
y1 = int(row["x1"])
@@ -189,6 +206,10 @@ def eval_segmentation_spiner(seg_dir, annotation_dir):
189206

190207
def print_accuracy(eval_dir):
191208
"""Print 'Precision', 'Recall', and 'F1-score' for dictionaries in a given directory.
209+
The directory is scanned for files containing ".dic.json" and evaluates segmentation accuracy and runtime.
210+
211+
Args:
212+
eval_dir: Print average accuracy of dictionary files in evaluation directory.
192213
"""
193214
eval_dicts = [entry.path for entry in os.scandir(eval_dir) if entry.is_file() and "dic.json" in entry.path]
194215
precision_list = []
@@ -224,6 +245,7 @@ def print_accuracy(eval_dir):
224245
recall_list.append(recall)
225246
f1_score_list.append(f1_score)
226247
time_list.append(time)
248+
227249
if show_time:
228250
param_list = [precision_list, recall_list, f1_score_list, time_list]
229251
names = ["Precision", "Recall", "F1 score", "Time"]
@@ -243,7 +265,7 @@ def print_accuracy_sgn():
243265
baselines = [
244266
"spiner2D",
245267
"cellpose3",
246-
"cellpose-sam_2025-10",
268+
"cellpose-sam",
247269
"distance_unet",
248270
"micro-sam",
249271
"stardist"]
@@ -260,7 +282,7 @@ def print_accuracy_ihc():
260282
seg_dir = os.path.join(cochlea_dir, "predictions/val_ihc")
261283
baselines = [
262284
"cellpose3",
263-
# "cellpose-sam_2025-11",
285+
"cellpose-sam",
264286
"distance_unet_v4b",
265287
"micro-sam"]
266288

0 commit comments

Comments
 (0)