Skip to content

Commit 0d8a9e8

Browse files
committed
Improve StarDist_cellpost script template
* Update to cellcast 0.3.0 API. * Add support for image stacks. * Move to a dedicated Appose category.
1 parent 88033f0 commit 0d8a9e8

2 files changed

Lines changed: 44 additions & 25 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#@script (language="appose-python")
2+
3+
# /// script
4+
# requires-python = ">=3.12,<3.13"
5+
# dependencies = ["cellcast>=0.3.0,<0.4", "appose>=0.12.0,<0.13"]
6+
# ///
7+
8+
#@ Img image
9+
#@output Img labels
10+
11+
#@ Double (value=1.0, description="minimum percentile value for normalization") pmin
12+
#@ Double (value=99.8, description="maximum percentile value for normalization") pmax
13+
#@ Double (value=0.479, description="Polygon probability threshold") prob_threshold
14+
#@ Double (value=0.3, description="Non-Maximum Suppression threshold") nms_threshold
15+
#@ Boolean gpu (value=true)
16+
17+
import numpy
18+
import cellcast
19+
20+
def stardist2d(data):
21+
return cellcast.models.StarDist2D.init_fluo(gpu=gpu).predict_fluo(
22+
data=data,
23+
pmin=pmin,
24+
pmax=pmax,
25+
prob_threshold=prob_threshold,
26+
nms_threshold=nms_threshold
27+
).astype("uint16")
28+
29+
dims = len(image.shape)
30+
31+
if dims == 2:
32+
labels = stardist2d(image)
33+
34+
elif dims == 3:
35+
label_slices = []
36+
slice_count = image.shape[0]
37+
for i in range(slice_count):
38+
task.update(f"Processing slice {i} of {slice_count}...", current=i, maximum=slice_count)
39+
slice = image[i,:,:]
40+
label_slices.append(stardist2d(slice))
41+
labels = numpy.stack(label_slices)
42+
43+
else:
44+
raise RuntimeError(f"Expected 2D or 3D image, but got {dims}-dimensional image")

‎src/main/resources/script_templates/appose-python/StarDist_cellcast.py‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)