Mercurial > repos > thomaswollmann > binary2labelimage
annotate binary2label.py @ 2:8f98926130d9 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
author | thomaswollmann |
---|---|
date | Wed, 12 Dec 2018 04:36:44 -0500 |
parents | 668f8dabb346 |
children |
rev | line source |
---|---|
0
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
1 import argparse |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
2 import sys |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
3 import skimage.io |
668f8dabb346
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 |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
5 import numpy as np |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
6 import warnings |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
7 from PIL import Image |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
8 |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
9 parser = argparse.ArgumentParser() |
668f8dabb346
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') |
668f8dabb346
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)') |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
12 args = parser.parse_args() |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
13 |
668f8dabb346
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 |
668f8dabb346
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) |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
16 |
668f8dabb346
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\binary2labelimage commit 77f1ea5beca40d8b5851fe366e84c32d5df5d6f8
thomaswollmann
parents:
diff
changeset
|
17 res = Image.fromarray(res) |
668f8dabb346
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") |