changeset 1:73d7a4ffc03d draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/split_image/ commit 6152e9fafda27f76c1e96e533143f86fe605e2da
author imgteam
date Sat, 12 Apr 2025 15:05:29 +0000
parents 6b42bec75e69
children
files split.py split_image.xml test-data/qyx.tiff test-data/qyx_q1.tiff test-data/qyx_q2.tiff test-data/rgb1_b.tiff test-data/rgb1_g.tiff test-data/rgb1_r.tiff test-data/rgb1_split_z.tiff test-data/rgb1_squeezed_b.tiff test-data/rgb1_squeezed_g.tiff test-data/rgb1_squeezed_r.tiff test-data/zcyx_slice01.tiff test-data/zcyx_slice25.tiff
diffstat 14 files changed, 29 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/split.py	Fri Mar 07 08:08:05 2025 +0000
+++ b/split.py	Sat Apr 12 15:05:29 2025 +0000
@@ -18,7 +18,7 @@
 assert len(args.axis) == 1, 'Axis input must be a single character.'
 axis = args.axis.replace('S', 'C')
 
-# Read input image as TZYXC
+# Read input image with normalized axes
 img_in = giatools.Image.read(args.input)
 
 # Determine the axis to split along
@@ -31,14 +31,24 @@
 for img_idx, img in enumerate(arr):
     img = np.moveaxis(img[None], 0, axis_pos)
 
+    # Construct the output image, remove axes added by normalization
+    img_out = giatools.Image(
+        data=img,
+        axes=img_in.axes,
+    ).squeeze_like(
+        img_in.original_axes,
+    )
+
     # 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
+        s = [
+            axis_pos for axis_pos in range(len(img_out.axes))
+            if img_out.data.shape[axis_pos] == 1 and img_out.axes[axis_pos] not in 'YX'
+        ]
+        img_out = img_out.squeeze_like(
+            giatools.util.str_without_positions(img_out.axes, s),
+        )
 
     # Save the result
     filename = output_filename_pattern % (img_idx + 1)
-    tifffile.imwrite(filename, img, metadata=dict(axes=img_axes))
+    tifffile.imwrite(filename, img_out.data, metadata=dict(axes=img_out.axes))
--- a/split_image.xml	Fri Mar 07 08:08:05 2025 +0000
+++ b/split_image.xml	Sat Apr 12 15:05:29 2025 +0000
@@ -4,7 +4,7 @@
         <import>creators.xml</import>
         <import>tests.xml</import>
         <token name="@TOOL_VERSION@">2.2.3</token>
-        <token name="@VERSION_SUFFIX@">0</token>
+        <token name="@VERSION_SUFFIX@">1</token>
     </macros>
     <creator>
         <expand macro="creators/bmcv"/>
@@ -14,7 +14,7 @@
     </edam_operations>
     <requirements>
         <requirement type="package" version="@TOOL_VERSION@">numpy</requirement>
-        <requirement type="package" version="0.3.2">giatools</requirement>
+        <requirement type="package" version="0.4.0">giatools</requirement>
         <requirement type="package" version="2024.7.24">tifffile</requirement>
     </requirements>
     <command detect_errors="aggressive"><![CDATA[
@@ -36,6 +36,7 @@
             <option value="Z">Z-axis (split the slices of a 3-D image or image sequence)</option>
             <option value="C" selected="true">C-axis (split the channels of an image or image sequence)</option>
             <option value="S">S-axis (split the samples of an image or image sequence)</option>
+            <option value="Q">Q-axis (other or unknown axis)</option>
         </param>
         <param name="squeeze" type="boolean" checked="false" truevalue="--squeeze" falsevalue="" label="Squeeze result imags" help="Only axes with more than one element will be retained in the result images. Does not apply for X and Y axes." />
     </inputs>
@@ -68,6 +69,15 @@
                 <expand macro="tests/intensity_image_diff/element" name="25.tiff" value="zcyx_slice25.tiff" ftype="tiff"/>
             </output_collection>
         </test>
+        <test>
+            <param name="input" value="qyx.tiff" />
+            <param name="axis" value="Q" />
+            <param name="squeeze" value="false" />
+            <output_collection name="output" type="list" count="2">
+                <expand macro="tests/intensity_image_diff/element" name="1.tiff" value="qyx_q1.tiff" ftype="tiff"/>
+                <expand macro="tests/intensity_image_diff/element" name="2.tiff" value="qyx_q2.tiff" ftype="tiff"/>
+            </output_collection>
+        </test>
 
         <!-- Test squeezing -->
         <test>
Binary file test-data/qyx.tiff has changed
Binary file test-data/qyx_q1.tiff has changed
Binary file test-data/qyx_q2.tiff has changed
Binary file test-data/rgb1_b.tiff has changed
Binary file test-data/rgb1_g.tiff has changed
Binary file test-data/rgb1_r.tiff has changed
Binary file test-data/rgb1_split_z.tiff has changed
Binary file test-data/rgb1_squeezed_b.tiff has changed
Binary file test-data/rgb1_squeezed_g.tiff has changed
Binary file test-data/rgb1_squeezed_r.tiff has changed
Binary file test-data/zcyx_slice01.tiff has changed
Binary file test-data/zcyx_slice25.tiff has changed