annotate count_objects.py @ 0:895a29ebd0c7 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:34:18 -0500
parents
children 664232d2a3f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 #!/usr/bin/python
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3 import argparse
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import numpy as np
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
5 import os
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6 import skimage.io
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 from skimage.measure import regionprops
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9 parser = argparse.ArgumentParser(description='Count Objects')
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10 parser.add_argument('input_file', type=argparse.FileType('r'),
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11 help='Label input file')
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 parser.add_argument('output_file', type=argparse.FileType('w'),
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 help='Tabular output file')
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 args = parser.parse_args()
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 img_raw = skimage.io.imread(args.input_file.name)
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17 res = len(regionprops(img_raw))
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19 text_file = open(args.output_file.name, "w")
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20 text_file.write("objects\n%s" % res)
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21 text_file.close()