annotate count_objects.py @ 2:803426d364aa draft default tip

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