Mercurial > repos > imgteam > binary2labelimage
annotate binary2label.py @ 1:37b99b904027 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
author | imgteam |
---|---|
date | Mon, 22 Jul 2019 04:55:34 -0400 |
parents | 1cde6ba34356 |
children | 938e2358eb80 |
rev | line source |
---|---|
0
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
1 import argparse |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
2 import sys |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
3 import skimage.io |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
4 from skimage.measure import label |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
5 import numpy as np |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
6 import warnings |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
7 from PIL import Image |
1
37b99b904027
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
0
diff
changeset
|
8 import skimage.util |
0
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
9 |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
10 parser = argparse.ArgumentParser() |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
11 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
12 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
13 args = parser.parse_args() |
1
37b99b904027
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
0
diff
changeset
|
14 |
0
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
15 img_in = skimage.io.imread(args.input_file.name) > 0 |
1
37b99b904027
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
0
diff
changeset
|
16 res = label(img_in) |
37b99b904027
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
0
diff
changeset
|
17 res = skimage.util.img_as_uint(res) |
0
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
18 |
1cde6ba34356
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
19 res = Image.fromarray(res) |
1
37b99b904027
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
0
diff
changeset
|
20 res.save(args.out_file.name, "tiff") |