Skip to content

Commit de13181

Browse files
Add stardist postprocessing script
1 parent d748003 commit de13181

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from glob import glob
3+
4+
from tifffile import imread, imwrite
5+
from csbdeep.utils import normalize
6+
from stardist.models import StarDist3D
7+
8+
model = StarDist3D.from_pretrained("3D_demo")
9+
10+
11+
def segment_with_stardist(ff, out):
12+
axis_norm = (0, 1, 2) # normalize channels independently
13+
x = imread(ff)
14+
img = normalize(x[0], 1, 99.8, axis=axis_norm)
15+
labels, details = model.predict_instances(img)
16+
imwrite(out, labels)
17+
18+
19+
def main():
20+
files = glob("predictions/sgn-new/*.tif")
21+
out_folder = "./predictions/stardist"
22+
os.makedirs(out_folder, exist_ok=True)
23+
for ff in files:
24+
out = imread(ff)
25+
segment_with_stardist(ff, out)
26+
27+
28+
if __name__ == "__main__":
29+
main()

0 commit comments

Comments
 (0)