Mercurial > repos > imgteam > concat_channels
view 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 |
line wrap: on
line source
import argparse import warnings import numpy as np import skimage.io import skimage.util def concat_channels(input_image_paths, output_image_path, axis): images = [] for image_path in input_image_paths: raw_image = skimage.io.imread(image_path) if len(raw_image.shape) == 2: if axis == 0: raw_image = [raw_image] else: raw_image = np.expand_dims(raw_image, 2) images.append(raw_image) res = np.concatenate(images, axis) with warnings.catch_warnings(): warnings.simplefilter("ignore") res = skimage.util.img_as_uint(res) # Attention: precision loss skimage.io.imsave(output_image_path, res, plugin='tifffile') if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+', help='input file') parser.add_argument('-o', dest='out_file', type=argparse.FileType('w'), help='out file (TIFF)') parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2], help='concatenation axis') args = parser.parse_args() concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis)