annotate count_objects.py @ 1:664232d2a3f7 draft

"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit 3d389fdec0db29cf6fbd783c0501455bf624fa90"
author imgteam
date Wed, 18 Dec 2019 05:01:56 -0500
parents 895a29ebd0c7
children 5bf8eb50b280
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
1
664232d2a3f7 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit 3d389fdec0db29cf6fbd783c0501455bf624fa90"
imgteam
parents: 0
diff changeset
7 from skimage.measure import regionprops
0
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')
1
664232d2a3f7 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit 3d389fdec0db29cf6fbd783c0501455bf624fa90"
imgteam
parents: 0
diff changeset
14 args = parser.parse_args()
0
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()