Mercurial > repos > imgteam > count_objects
annotate count_objects.py @ 0:784d5cf56c82 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:16:39 -0500 |
parents | |
children | faa34f06aa6c |
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 |
784d5cf56c82
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 |
784d5cf56c82
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
5 import os |
784d5cf56c82
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
6 import skimage.io |
784d5cf56c82
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 |
784d5cf56c82
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
8 |
784d5cf56c82
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') |
784d5cf56c82
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'), |
784d5cf56c82
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') |
784d5cf56c82
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'), |
784d5cf56c82
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') |
784d5cf56c82
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() |
784d5cf56c82
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
15 |
784d5cf56c82
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) |
784d5cf56c82
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)) |
784d5cf56c82
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
18 |
784d5cf56c82
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") |
784d5cf56c82
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) |
784d5cf56c82
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
21 text_file.close() |