Skip to content

Commit 43bfda9

Browse files
Merge branch 'intensity-masking' of https://github.com/computational-cell-analytics/lightsheet-moser into intensity-masking
2 parents cab37c0 + 2d929c4 commit 43bfda9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
direc = "/mnt/vast-nhr/projects/nim00007/data/moser/predictions/sgn-new"
21+
out_folder = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/predictions/stardist"
22+
23+
files = [entry.path for entry in os.scandir(direc) if ".tif" in entry.name]
24+
files.sort()
25+
file_names = [entry.name.split(".tif")[0] for entry in os.scandir(direc) if ".tif" in entry.name]
26+
file_names.sort()
27+
28+
os.makedirs(out_folder, exist_ok=True)
29+
for f_path, f_name in zip(files, file_names):
30+
out = os.path.join(out_folder, f"{f_name}_seg.tif")
31+
segment_with_stardist(f_path, out)
32+
33+
34+
if __name__ == "__main__":
35+
main()

0 commit comments

Comments
 (0)