# HG changeset patch # User imgteam # Date 1741334885 0 # Node ID 6b42bec75e69c333d0250fd4e7e966ff56656556 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/split_image/ commit f1052360d410594fa1795cf0e02576b8fa4d4135 diff -r 000000000000 -r 6b42bec75e69 creators.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/creators.xml Fri Mar 07 08:08:05 2025 +0000 @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r 6b42bec75e69 split.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/split.py Fri Mar 07 08:08:05 2025 +0000 @@ -0,0 +1,44 @@ +import argparse +import math + +import giatools +import giatools.util +import numpy as np +import tifffile + + +parser = argparse.ArgumentParser() +parser.add_argument('input', type=str) +parser.add_argument('axis', type=str) +parser.add_argument('output', type=str) +parser.add_argument('--squeeze', action='store_true', default=False) +args = parser.parse_args() + +# Validate and normalize input parameters +assert len(args.axis) == 1, 'Axis input must be a single character.' +axis = args.axis.replace('S', 'C') + +# Read input image as TZYXC +img_in = giatools.Image.read(args.input) + +# Determine the axis to split along +axis_pos = img_in.axes.index(axis) + +# Perform the splitting +arr = np.moveaxis(img_in.data, axis_pos, 0) +decimals = math.ceil(math.log10(1 + arr.shape[0])) +output_filename_pattern = f'{args.output}/%0{decimals}d.tiff' +for img_idx, img in enumerate(arr): + img = np.moveaxis(img[None], 0, axis_pos) + + # Optionally, squeeze the image + if args.squeeze: + s = [axis_pos for axis_pos in range(len(img_in.axes)) if img.shape[axis_pos] == 1 and img_in.axes[axis_pos] not in 'YX'] + img = np.squeeze(img, axis=tuple(s)) + img_axes = giatools.util.str_without_positions(img_in.axes, s) + else: + img_axes = img_in.axes + + # Save the result + filename = output_filename_pattern % (img_idx + 1) + tifffile.imwrite(filename, img, metadata=dict(axes=img_axes)) diff -r 000000000000 -r 6b42bec75e69 split_image.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/split_image.xml Fri Mar 07 08:08:05 2025 +0000 @@ -0,0 +1,108 @@ + + with NumPy + + creators.xml + tests.xml + 2.2.3 + 0 + + + + + + operation_3443 + + + numpy + giatools + tifffile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + **Splits an image along a specific axis (e.g., channels).** + + This tool splits an image along a specifc axis and yields a collection of images. + This can be used, for example, to convert a multi-channel image into a collection of single-channel images. + + The pixel data type of the split image is preserved (will be the same as the input image). + + + + 10.1038/s41586-020-2649-2 + + diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1.png Binary file test-data/rgb1.png has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_b.tiff Binary file test-data/rgb1_b.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_g.tiff Binary file test-data/rgb1_g.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_r.tiff Binary file test-data/rgb1_r.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_split_z.tiff Binary file test-data/rgb1_split_z.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_squeezed_b.tiff Binary file test-data/rgb1_squeezed_b.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_squeezed_g.tiff Binary file test-data/rgb1_squeezed_g.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/rgb1_squeezed_r.tiff Binary file test-data/rgb1_squeezed_r.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/zcyx.tiff Binary file test-data/zcyx.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/zcyx_slice01.tiff Binary file test-data/zcyx_slice01.tiff has changed diff -r 000000000000 -r 6b42bec75e69 test-data/zcyx_slice25.tiff Binary file test-data/zcyx_slice25.tiff has changed diff -r 000000000000 -r 6b42bec75e69 tests.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests.xml Fri Mar 07 08:08:05 2025 +0000 @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +