Mercurial > repos > thomaswollmann > binary2labelimage
annotate binary2label.py @ 0:4f07ac917459 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
| author | thomaswollmann | 
|---|---|
| date | Sat, 11 Feb 2017 17:28:38 -0500 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 1 import argparse | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 2 import sys | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 3 import skimage.io | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 4 from skimage.measure import label | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 5 import numpy as np | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 6 import warnings | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 7 from PIL import Image | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 8 | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 9 parser = argparse.ArgumentParser() | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 10 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 11 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 12 args = parser.parse_args() | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 13 | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 14 img_in = skimage.io.imread(args.input_file.name) > 0 | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 15 res = label(img_in).astype(np.int32) | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 16 | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 17 res = Image.fromarray(res) | 
| 
4f07ac917459
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
 thomaswollmann parents: diff
changeset | 18 res.save(args.out_file.name, "tiff") | 
