annotate label_to_binary.py @ 0:5da15c3bafed draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
author imgteam
date Wed, 13 Mar 2024 14:55:31 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
1 import argparse
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
2
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
3 import numpy as np
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
4 import skimage.io
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
5
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
6
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
7 if __name__ == '__main__':
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
8
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
9 parser = argparse.ArgumentParser()
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
10 parser.add_argument('input', type=str)
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
11 parser.add_argument('bg_label', type=int)
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
12 parser.add_argument('output', type=str)
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
13 args = parser.parse_args()
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
14
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
15 im = skimage.io.imread(args.input)
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
16 im = (im != args.bg_label)
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
17 im = (im * 255).astype(np.uint8)
5da15c3bafed planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ commit 0a64a49d4a0ac3438544244a8b871be2fc144766
imgteam
parents:
diff changeset
18 skimage.io.imsave(args.output, im)