annotate count_objects.py @ 3:b58447a2eed2 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/count_objects/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author imgteam
date Mon, 13 Nov 2023 22:10:56 +0000
parents 5bf8eb50b280
children
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
2
5bf8eb50b280 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit 3c2a4fed433e518fcd0bc8d4deffcc5c2346b2b5
imgteam
parents: 1
diff changeset
4
0
895a29ebd0c7 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
5bf8eb50b280 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
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7
895a29ebd0c7 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')
895a29ebd0c7 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'),
895a29ebd0c7 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')
895a29ebd0c7 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'),
895a29ebd0c7 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
5bf8eb50b280 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
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14
895a29ebd0c7 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)
895a29ebd0c7 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))
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17
895a29ebd0c7 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")
895a29ebd0c7 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)
895a29ebd0c7 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20 text_file.close()