Mercurial > repos > thomaswollmann > count_objects
annotate count_objects.py @ 0:f02a2d0f407c draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
| author | thomaswollmann | 
|---|---|
| date | Wed, 16 Jan 2019 15:34:44 -0500 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 1 #!/usr/bin/python | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 2 | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 3 import argparse | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 4 import numpy as np | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 5 import os | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 6 import skimage.io | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 7 from skimage.measure import regionprops | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 8 | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 9 parser = argparse.ArgumentParser(description='Count Objects') | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 10 parser.add_argument('input_file', type=argparse.FileType('r'), | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 11 help='Label input file') | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 12 parser.add_argument('output_file', type=argparse.FileType('w'), | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 13 help='Tabular output file') | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 14 args = parser.parse_args() | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 15 | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 16 img_raw = skimage.io.imread(args.input_file.name) | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 17 res = len(regionprops(img_raw)) | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 18 | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 19 text_file = open(args.output_file.name, "w") | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 20 text_file.write("objects\n%s" % res) | 
| 
f02a2d0f407c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/count_objects/ commit d93e1dd276027cfc3fb518236110395a23d96f66
 thomaswollmann parents: diff
changeset | 21 text_file.close() | 
