# HG changeset patch # User imgteam # Date 1712244329 0 # Node ID 4c43875c790cbf2bff7ce79474a24fa4d578b7cd # Parent 212627bfb759df364da5522d26bf6de5148457a6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/concat_channels/ commit c045f067a57e8308308cf6329060c7ccd3fc372f diff -r 212627bfb759 -r 4c43875c790c concat_channels.py --- a/concat_channels.py Mon Nov 13 22:10:47 2023 +0000 +++ b/concat_channels.py Thu Apr 04 15:25:29 2024 +0000 @@ -1,33 +1,42 @@ import argparse -import warnings import numpy as np import skimage.io import skimage.util -def concat_channels(input_image_paths, output_image_path, axis): +def concat_channels(input_image_paths, output_image_path, axis, preserve_values): 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) + + # Preserve values: Convert to `float` dtype without changing the values + if preserve_values: + raw_image = raw_image.astype(float) + + # Preserve brightness: Scale values to 0..1 + else: + raw_image = skimage.util.img_as_float(raw_image) + images.append(raw_image) + + # Do the concatenation and save 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') + 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') + parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+') + parser.add_argument('-o', dest='out_file', type=argparse.FileType('w')) + parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2]) + parser.add_argument('--preserve_values', default=False, action='store_true') args = parser.parse_args() - concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis) + concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis, args.preserve_values) diff -r 212627bfb759 -r 4c43875c790c concat_channels.xml --- a/concat_channels.xml Mon Nov 13 22:10:47 2023 +0000 +++ b/concat_channels.xml Thu Apr 04 15:25:29 2024 +0000 @@ -1,5 +1,12 @@ - + + + creators.xml + tests.xml + + + + operation_3443 @@ -7,40 +14,71 @@ galaxy_image_analysis - scikit-image - numpy - tifffile + scikit-image + numpy + tifffile - - - + + ]]> - - - - + + + + + + - + + + + + + + + - + + + + + - **What it does** + + **Concatenates images along arbitrary axes.** - This tool concatenates images. + This can be used, for example, to spatially concatenate images, or along their channels. + + This tool either preserves the image brightness, or the range of values. + In general, both cannot be preserved when concatenating images of different pixel types (e.g., uint8 and uint16). + 10.1016/j.jbiotec.2017.07.019 diff -r 212627bfb759 -r 4c43875c790c creators.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/creators.xml Thu Apr 04 15:25:29 2024 +0000 @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff -r 212627bfb759 -r 4c43875c790c test-data/input1_uint8.png Binary file test-data/input1_uint8.png has changed diff -r 212627bfb759 -r 4c43875c790c test-data/input2_float.tiff Binary file test-data/input2_float.tiff has changed diff -r 212627bfb759 -r 4c43875c790c test-data/out.tiff Binary file test-data/out.tiff has changed diff -r 212627bfb759 -r 4c43875c790c test-data/res.tiff Binary file test-data/res.tiff has changed diff -r 212627bfb759 -r 4c43875c790c test-data/res_preserve_brightness.tiff Binary file test-data/res_preserve_brightness.tiff has changed diff -r 212627bfb759 -r 4c43875c790c test-data/res_preserve_values.tiff Binary file test-data/res_preserve_values.tiff has changed diff -r 212627bfb759 -r 4c43875c790c test-data/sample1.png Binary file test-data/sample1.png has changed diff -r 212627bfb759 -r 4c43875c790c test-data/sample2.png Binary file test-data/sample2.png has changed diff -r 212627bfb759 -r 4c43875c790c tests.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests.xml Thu Apr 04 15:25:29 2024 +0000 @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +