Mercurial > repos > thomaswollmann > binary2labelimage
annotate binary2label.py @ 2:ded33b6956c6 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
author | thomaswollmann |
---|---|
date | Fri, 07 Dec 2018 08:04:56 -0500 |
parents | 4f07ac917459 |
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") |