changeset 5:8d50a0a9e4af draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/concat_channels/ commit 4573c7c050968a40f6377a95727694105fbd69c7
author imgteam
date Sun, 07 Dec 2025 16:16:03 +0000
parents 2592a29a785e
children
files concat_channels.py concat_channels.xml creators.xml
diffstat 3 files changed, 104 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/concat_channels.py	Wed Apr 24 08:12:22 2024 +0000
+++ b/concat_channels.py	Sun Dec 07 16:16:03 2025 +0000
@@ -1,43 +1,59 @@
 import argparse
 
-import giatools.io
+import giatools
 import numpy as np
 import skimage.io
 import skimage.util
 
 
-def concat_channels(input_image_paths, output_image_path, axis, preserve_values):
+normalized_axes = 'QTZYXC'
+
+
+def concat_channels(
+    input_image_paths: list[str],
+    output_image_path: str,
+    axis: str,
+    preserve_values: bool,
+):
+    # Create list of arrays to be concatenated
     images = []
     for image_path in input_image_paths:
 
-        raw_image = giatools.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)
+        img = giatools.Image.read(image_path, normalize_axes=normalized_axes)
+        arr = img.data
 
         # Preserve values: Convert to `float` dtype without changing the values
         if preserve_values:
-            raw_image = raw_image.astype(float)
+            arr = arr.astype(float)
 
         # Preserve brightness: Scale values to 0..1
         else:
-            raw_image = skimage.util.img_as_float(raw_image)
+            arr = skimage.util.img_as_float(arr)
 
-        images.append(raw_image)
+        images.append(arr)
 
-    # Do the concatenation and save
-    res = np.concatenate(images, axis)
-    skimage.io.imsave(output_image_path, res, plugin='tifffile')
+    # Do the concatenation
+    axis_pos = normalized_axes.index(axis)
+    arr = np.concatenate(images, axis_pos)
+    res = giatools.Image(arr, normalized_axes)
+
+    # Squeeze singleton axes and save
+    squeezed_axes = ''.join(np.array(list(res.axes))[np.array(arr.shape) > 1])
+    res = res.squeeze_like(squeezed_axes)
+    res.write(output_image_path, backend='tifffile')
 
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
-    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('input_files', type=str, nargs='+')
+    parser.add_argument('out_file', type=str)
+    parser.add_argument('axis', type=str)
     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, args.preserve_values)
+    concat_channels(
+        args.input_files,
+        args.out_file,
+        args.axis,
+        args.preserve_values,
+    )
--- a/concat_channels.xml	Wed Apr 24 08:12:22 2024 +0000
+++ b/concat_channels.xml	Sun Dec 07 16:16:03 2025 +0000
@@ -1,4 +1,4 @@
-<tool id="ip_concat_channels" name="Concatenate images or channels" version="0.3-1" profile="20.05">
+<tool id="ip_concat_channels" name="Concatenate images or channels" version="0.4" profile="20.05">
     <description></description>
     <macros>
         <import>creators.xml</import>
@@ -14,10 +14,10 @@
         <xref type="bio.tools">galaxy_image_analysis</xref>
     </xrefs>
     <requirements>
-        <requirement type="package" version="0.18.3">scikit-image</requirement>
-        <requirement type="package" version="1.24.1">numpy</requirement>
-        <requirement type="package" version="2021.7.2">tifffile</requirement>
-        <requirement type="package" version="0.1">giatools</requirement>
+        <requirement type="package" version="0.25.2">scikit-image</requirement>
+        <requirement type="package" version="2.3.5">numpy</requirement>
+        <requirement type="package" version="2025.10.16">tifffile</requirement>
+        <requirement type="package" version="0.4.1">giatools</requirement>
     </requirements>
     <command detect_errors="aggressive"><![CDATA[
 
@@ -27,15 +27,23 @@
             '$input'
         #end for
 
-        $mode
+        '$output'
+        '$axis'
 
-        -o '$output' --axis '$axis'
+        $mode
 
     ]]></command>
     <inputs>
         <param name="inputs" type="data" multiple="true" format="tiff,png" label="Images to concatenate"/>
-        <param name="axis" type="integer" min="0" value="0" label="Concatenation axis" help="The images will be concatenated along this axis. For a 2-D image, a value of 0 corresponds to horizontal concatenation, and a value of 1 to vertical concatenation. For an RGB image, a value of 2 corresponds to concatenation of the channels of the images."/>
-        <param name="mode" type="select" label="Scaling of values" help="If the brightness is to be preserved (default), then the values will be scaled between 0 and 1, and the pixel type will be float.">
+        <param name="axis" type="select" label="Concatenation axis" help="The images will be concatenated along this axis.">
+            <option value="X">X-axis (concatenate images or image sequences horizontally)</option>
+            <option value="Y">Y-axis (concatenate images or image sequences vertically)</option>
+            <option value="T">T-axis (concatenate images as frames of a temporal image sequence)</option>
+            <option value="Z">Z-axis (concatenate images as slices of a 3-D image or image sequence)</option>
+            <option value="C" selected="true">C-axis (concatenate the channels/samples of images or image sequences)</option>
+            <option value="Q">Q-axis (concatenate along other or unknown axis)</option>
+        </param>
+        <param name="mode" type="select" label="Scaling of values" help="If the brightness is to be preserved (default), then the values will be scaled between 0 and 1, and a floating point pixel data type will be used.">
             <option value="" selected="true">Preserve brightness</option>
             <option value="--preserve_values">Preserve range of values</option>
         </param>
@@ -44,17 +52,17 @@
         <data format="tiff" name="output"/>
     </outputs>
     <tests>
-        <!-- Test with "preserve brightness" -->
+        <!-- Test with "preserve brightness", vertical concatenation -->
         <test>
             <param name="inputs" value="input1_uint8.png,input2_float.tiff"/>
-            <param name="axis" value="0"/>
+            <param name="axis" value="Y"/>
             <param name="mode" value=""/>
             <expand macro="tests/intensity_image_diff" name="output" value="res_preserve_brightness.tiff" ftype="tiff"/>
         </test>
-        <!-- Test with "preserve range of values" -->
+        <!-- Test with "preserve range of values", vertical concatenation -->
         <test>
             <param name="inputs" value="input1_uint8.png,input2_float.tiff"/>
-            <param name="axis" value="0"/>
+            <param name="axis" value="Y"/>
             <param name="mode" value="--preserve_values"/>
             <expand macro="tests/intensity_image_diff" name="output" value="res_preserve_values.tiff" ftype="tiff">
                 <!--
@@ -70,6 +78,34 @@
                 <has_image_mean_intensity min="0" max="255"/>
             </expand>
         </test>
+        <!-- Test concatenation of channels (axis *exists* in both images) -->
+        <test>
+            <param name="inputs" value="input1_uint8.png,input2_float.tiff"/>
+            <param name="axis" value="C"/>
+            <output name="output" ftype="tiff">
+                <assert_contents>
+                    <has_image_width width="119"/>
+                    <has_image_height height="119"/>
+                    <has_image_depth depth="1"/>
+                    <has_image_channels channels="8"/>
+                    <has_image_frames frames="1"/>
+                </assert_contents>
+            </output>
+        </test>
+        <!-- Test concatenation of frames (axis *does not* exist in both images) -->
+        <test>
+            <param name="inputs" value="input1_uint8.png,input2_float.tiff"/>
+            <param name="axis" value="T"/>
+            <output name="output" ftype="tiff">
+                <assert_contents>
+                    <has_image_width width="119"/>
+                    <has_image_height height="119"/>
+                    <has_image_depth depth="1"/>
+                    <has_image_channels channels="4"/>
+                    <has_image_frames frames="2"/>
+                </assert_contents>
+            </output>
+        </test>
     </tests>
     <help>
 
--- a/creators.xml	Wed Apr 24 08:12:22 2024 +0000
+++ b/creators.xml	Sun Dec 07 16:16:03 2025 +0000
@@ -5,6 +5,16 @@
         <yield />
     </xml>
 
+    <xml name="creators/kostrykin">
+        <person givenName="Leonid" familyName="Kostrykin"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/rmassei">
+        <person givenName="Riccardo" familyName="Massei"/>
+        <yield/>
+    </xml>
+
     <xml name="creators/alliecreason">
         <person givenName="Allison" familyName="Creason"/>
         <yield/>
@@ -19,5 +29,15 @@
         <person givenName="Till" familyName="Korten"/>
         <yield/>
     </xml>
-    
+
+    <xml name="creators/pavanvidem">
+        <person givenName="Pavan" familyName="Videm"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/tuncK">
+        <person givenName="Tunc" familyName="Kayikcioglu"/>
+        <yield/>
+    </xml>
+
 </macros>