Skip to content

Commit 12799b1

Browse files
committed
Script for counting cells in segmentation
1 parent 230b806 commit 12799b1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts/prediction/count_cells.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import argparse
2+
import os
3+
import sys
4+
5+
from elf.parallel import unique
6+
from elf.io import open_file
7+
8+
sys.path.append("../..")
9+
10+
11+
def main():
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument("-o", "--output_folder", type=str, required=True, help="Output directory containing segmentation.zarr")
14+
parser.add_argument("-m", "--min_size", type=int, default=1000, help="Minimal number of voxel size for counting object")
15+
args = parser.parse_args()
16+
17+
seg_path = os.path.join(args.output_folder, "segmentation.zarr")
18+
seg_key = "segmentation"
19+
20+
file = open_file(seg_path, mode='r')
21+
dataset = file[seg_key]
22+
23+
ids, counts = unique(dataset, return_counts=True)
24+
25+
# You can change the minimal size for objects to be counted here:
26+
min_size = args.min_size
27+
28+
counts = counts[counts > min_size]
29+
print("Number of objects:", len(counts))
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)