Mercurial > repos > imgteam > concat_channels
comparison concat_channels.py @ 2:212627bfb759 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/concat_channels/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author | imgteam |
---|---|
date | Mon, 13 Nov 2023 22:10:47 +0000 |
parents | d42501109c05 |
children | 4c43875c790c |
comparison
equal
deleted
inserted
replaced
1:d42501109c05 | 2:212627bfb759 |
---|---|
1 import argparse | 1 import argparse |
2 import sys | |
3 import warnings | 2 import warnings |
3 | |
4 import numpy as np | 4 import numpy as np |
5 import skimage.io | 5 import skimage.io |
6 import skimage.util | 6 import skimage.util |
7 | |
7 | 8 |
8 def concat_channels(input_image_paths, output_image_path, axis): | 9 def concat_channels(input_image_paths, output_image_path, axis): |
9 images = [] | 10 images = [] |
10 for image_path in input_image_paths: | 11 for image_path in input_image_paths: |
11 raw_image = skimage.io.imread(image_path) | 12 raw_image = skimage.io.imread(image_path) |
12 if len(raw_image.shape) == 2: | 13 if len(raw_image.shape) == 2: |
13 if axis == 0: | 14 if axis == 0: |
14 raw_image = [raw_image] | 15 raw_image = [raw_image] |
15 else: | 16 else: |
16 raw_image = np.expand_dims(raw_image, 2) | 17 raw_image = np.expand_dims(raw_image, 2) |
17 images.append(raw_image) | 18 images.append(raw_image) |
18 res = np.concatenate(images, axis) | 19 res = np.concatenate(images, axis) |
19 with warnings.catch_warnings(): | 20 with warnings.catch_warnings(): |
20 warnings.simplefilter("ignore") | 21 warnings.simplefilter("ignore") |
21 res = skimage.util.img_as_uint(res) #Attention: precision loss | 22 res = skimage.util.img_as_uint(res) # Attention: precision loss |
22 skimage.io.imsave(output_image_path, res, plugin='tifffile') | 23 skimage.io.imsave(output_image_path, res, plugin='tifffile') |
24 | |
23 | 25 |
24 if __name__ == "__main__": | 26 if __name__ == "__main__": |
25 parser = argparse.ArgumentParser() | 27 parser = argparse.ArgumentParser() |
26 parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+', help='input file') | 28 parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+', help='input file') |
27 parser.add_argument('-o', dest='out_file', type=argparse.FileType('w'), help='out file (TIFF)') | 29 parser.add_argument('-o', dest='out_file', type=argparse.FileType('w'), help='out file (TIFF)') |
28 parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0,2], help='concatenation axis') | 30 parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2], help='concatenation axis') |
29 args = parser.parse_args() | 31 args = parser.parse_args() |
30 | 32 |
31 # print([x.name for x in args.input_files], args.out_file.name, args.axis) | |
32 concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis) | 33 concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis) |
33 # concat_channels(args.input_files, args.out_file, args.axis) |