annotate binary2label.py @ 4:984358e43242 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 00199464fa2aa1928a49e2379edf199c3db91533
author imgteam
date Tue, 14 Nov 2023 08:27:27 +0000
parents 9bb446db4a1e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import sys
3
9bb446db4a1e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 2
diff changeset
3
0
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import skimage.io
3
9bb446db4a1e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 2
diff changeset
5 import skimage.util
9bb446db4a1e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 2
diff changeset
6 from PIL import Image
0
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 from skimage.measure import label
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9 parser = argparse.ArgumentParser()
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
3
9bb446db4a1e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 2
diff changeset
11 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
0
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 args = parser.parse_args()
3
9bb446db4a1e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 2
diff changeset
13
0
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 img_in = skimage.io.imread(args.input_file.name) > 0
1
6c92ac9ce868 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents: 0
diff changeset
15 res = label(img_in)
6c92ac9ce868 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents: 0
diff changeset
16 res = skimage.util.img_as_uint(res)
0
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17
b97a362ff321 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18 res = Image.fromarray(res)
1
6c92ac9ce868 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binary2labelimage/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents: 0
diff changeset
19 res.save(args.out_file.name, "tiff")