changeset 3:eb173a1fabc4 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/overlay_images/ commit 574caf027453f080a7f86f80eae9775ed1c8afa0
author imgteam
date Mon, 23 Sep 2024 10:26:14 +0000
parents f42d21fe65d8
children
files creators.xml overlay_images.py overlay_images.xml test-data/sample1.tif test-data/sample1_uint16.tif test-data/sample1_uint8.tif test-data/sample1_uint8_rgb.png test-data/test3.png test-data/test3.tif test-data/test4.png test-data/test4.tif test-data/test5.png tests.xml
diffstat 13 files changed, 214 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/creators.xml	Mon Sep 23 10:26:14 2024 +0000
@@ -0,0 +1,28 @@
+<macros>
+
+    <xml name="creators/bmcv">
+        <organization name="Biomedical Computer Vision Group, Heidelberg Universtiy" alternateName="BMCV" url="http://www.bioquant.uni-heidelberg.de/research/groups/biomedical_computer_vision.html" />
+        <yield />
+    </xml>
+
+    <xml name="creators/rmassei">
+        <person givenName="Riccardo" familyName="Massei"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/alliecreason">
+        <person givenName="Allison" familyName="Creason"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/bugraoezdemir">
+        <person givenName="Bugra" familyName="Oezdemir"/>
+        <yield/>
+    </xml>
+
+    <xml name="creators/thawn">
+        <person givenName="Till" familyName="Korten"/>
+        <yield/>
+    </xml>
+    
+</macros>
--- a/overlay_images.py	Thu Aug 10 07:29:24 2023 +0000
+++ b/overlay_images.py	Mon Sep 23 10:26:14 2024 +0000
@@ -7,6 +7,7 @@
 
 import argparse
 
+import giatools.io
 import matplotlib.colors
 import matplotlib.pyplot as plt
 import numpy as np
@@ -18,7 +19,7 @@
 
 
 def read_im_gray(fn):
-    img = skimage.io.imread(fn)
+    img = giatools.io.imread(fn)
     nDims = len(img.shape)
     assert nDims in [2, 3], 'this tool only supports single 2D images'
     if nDims == 3 and img.shape[-1] in [3, 4]:
@@ -33,15 +34,17 @@
     img = np.squeeze(img)
     assert img.ndim == 2 or (img.ndim == 3 and img.shape[-1] in (3, 4))
     if str(img.dtype).startswith('float'):
-        img = np.round(img * 255).astype('uint8')
-    elif img.dtype == 'uint16':
-        img = img // 256
-    elif img.dtype != 'uint8':
+        img = np.round(img * 255).astype(np.uint8)
+    elif img.dtype == np.uint16:
+        img = (img // 256).astype(np.uint8)
+    elif img.dtype != np.uint8:
         raise ValueError(f'unknown dtype: {img.dtype}')
     if img.ndim == 2:
-        return np.dstack([img] * 3).copy()
+        result = np.dstack([img] * 3).copy()
     else:
-        return img[:, :, :3].copy()
+        result = img[:, :, :3].copy()
+    assert result.dtype == np.uint8, result.dtype
+    return result
 
 
 def coloc_vis(in_red_fn, in_green_fn, out_fn):
@@ -59,8 +62,8 @@
 
 
 def blending(im1_fn, im2_fn, out_fn, alpha=0.5):
-    im1 = skimage.io.imread(im1_fn)
-    im2 = skimage.io.imread(im2_fn)
+    im1 = giatools.io.imread(im1_fn)
+    im2 = giatools.io.imread(im2_fn)
     assert im1.shape == im2.shape, 'Two images should have the same dimension'
     out_im = (1 - alpha) * im1 + alpha * im2
     if len(im1.shape) > 3:
@@ -70,8 +73,8 @@
 
 
 def seg_contour(im1_fn, im2_fn, out_fn, linewidth, color='#ff0000', show_label=False, label_color='#ffff00'):
-    img = skimage.io.imread(im1_fn)
-    labels = skimage.io.imread(im2_fn)
+    img = giatools.io.imread(im1_fn)
+    labels = giatools.io.imread(im2_fn)
 
     result = get_rgb8_copy(img)
     cp = ContourPaint(labels, linewidth, where='center')
--- a/overlay_images.xml	Thu Aug 10 07:29:24 2023 +0000
+++ b/overlay_images.xml	Mon Sep 23 10:26:14 2024 +0000
@@ -1,15 +1,38 @@
-<tool id="ip_overlay_images" name="Overlay Images" version="0.0.3" profile="20.05"> 
-    <description>for visualization</description>
+<tool id="ip_overlay_images" name="Overlay images" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
+    <description></description>
+    <macros>
+        <import>creators.xml</import>
+        <import>tests.xml</import>
+        <token name="@TOOL_VERSION@">0.0.4</token>
+        <token name="@VERSION_SUFFIX@">4</token>
+    </macros>
+    <creator>
+        <expand macro="creators/bmcv"/>
+        <expand macro="creators/thawn"/>
+    </creator>
+    <edam_operations>
+        <edam_operation>operation_3443</edam_operation>
+    </edam_operations>
+    <xrefs>
+        <xref type="bio.tools">galaxy_image_analysis</xref>
+    </xrefs>
     <requirements>
         <requirement type="package" version="0.18.1">scikit-image</requirement> 
         <requirement type="package" version="3.3.4">matplotlib</requirement>
         <requirement type="package" version="2020.10.1">tifffile</requirement>
-        <requirement type="package" version="1.20.2">numpy</requirement>
+        <requirement type="package" version="1.21">numpy</requirement>
+        <requirement type="package" version="10.4.0">pillow</requirement>
+        <requirement type="package" version="0.1">giatools</requirement>
     </requirements>
     <command detect_errors="aggressive">
     <![CDATA[
         python '$__tool_directory__/overlay_images.py'
-        '$method_option.im1' '$method_option.im2' ./output.tif
+        '$method_option.im1' '$method_option.im2'
+        #if $method_option.method == "seg_contour"
+            ./output.png
+        #else
+            ./output.tif
+        #end if
         --method $method_option.method
         #if $method_option.method == "blending"
             --alpha $method_option.alpha
@@ -23,23 +46,23 @@
     </command>
     <inputs>
         <conditional name="method_option">
-            <param name="method" type="select" label="How to visualize the overlay?">
+            <param name="method" type="select" label="Type of the overlay">
                 <option value="coloc_vis" selected="True">Colocalization</option>
-                <option value="blending">Blending</option>
-                <option value="seg_contour">Segmentation mask over image</option>
+                <option value="blending">Linear blending</option>
+                <option value="seg_contour">Segmentation contours over image</option>
             </param>
             <when value="coloc_vis">
-                <param name="im1" type="data" format="tiff,png" label="Image #1 (red channel)" />
-                <param name="im2" type="data" format="tiff,png" label="Image #2 (green channel)" />
+                <param name="im1" type="data" format="tiff,png" label="Image 1 (red channel)" />
+                <param name="im2" type="data" format="tiff,png" label="Image 2 (green channel)" />
             </when>
             <when value="blending">
-                <param name="im1" type="data" format="tiff,png" label="Image #1" />
-                <param name="im2" type="data" format="tiff,png" label="Image #2" />
-                <param name="alpha" type="float" value="0.5" min="0.0" max="1.0" label="The weight for blending: I_out = (1 - w) * I_1 + w * I_2."/>
+                <param name="im1" type="data" format="tiff,png" label="Image 1" />
+                <param name="im2" type="data" format="tiff,png" label="Image 2" />
+                <param name="alpha" type="float" value="0.5" min="0.0" max="1.0" label="The weight for blending: result = (1 - weight) * image1 + weight * image2." />
             </when>
             <when value="seg_contour">
-                <param name="im1" type="data" format="tiff,png" label="Image" />
-                <param name="im2" type="data" format="tiff,png" label="Label image" />
+                <param name="im1" type="data" format="tiff,png" label="Intensity image" />
+                <param name="im2" type="data" format="tiff,png" label="Label map" />
                 <param name="thickness" type="integer" value="2" min="1" label="Contour thickness (in pixels)" />
                 <param name="color" type="color" value="#ff0000" label="Contour color"/>
                 <param argument="--show_label" type="boolean" checked='false' truevalue="--show_label" falsevalue="" label="Show labels" />
@@ -48,45 +71,70 @@
         </conditional>
     </inputs>
     <outputs>
-        <data format="tiff" name="out" from_work_dir="output.tif" />
+        <data format="tiff" name="out_tiff" from_work_dir="output.tif" label="${tool.name} on ${on_string} output:tiff">
+            <filter>method_option['method'] != 'seg_contour'</filter>
+        </data>
+        <data format="png" name="out_png" from_work_dir="output.png" label="${tool.name} on ${on_string} output:png">
+            <filter>method_option['method'] == 'seg_contour'</filter>
+        </data>
     </outputs>
     <tests>
-        <test>
+        <test expect_num_outputs="1">
             <param name="im1" value="mask1.tif"/>
             <param name="im2" value="mask1r.tif"/>
             <param name="method" value="coloc_vis"/>
-            <output name="out" value="test1.tif" ftype="tiff" compare="sim_size" delta_frac="0.1"/>
+            <expand macro="tests/intensity_image_diff" name="out_tiff" value="test1.tif" ftype="tiff"/>
         </test>
-        <test>
+        <test expect_num_outputs="1">
             <param name="im1" value="mask1.tif"/>
             <param name="im2" value="mask1r.tif"/>
             <param name="method" value="blending"/>
             <param name="alpha" value="0.3"/>
-            <output name="out" value="test2.tif" ftype="tiff" compare="sim_size" delta_frac="0.1"/>
+            <expand macro="tests/intensity_image_diff" name="out_tiff" value="test2.tif" ftype="tiff"/>
         </test>
-        <test>
-            <param name="im1" value="sample1.tif"/>
+        <test expect_num_outputs="1">
+            <param name="im1" value="sample1_uint8.tif"/>
             <param name="im2" value="mask1.tif"/>
             <param name="method" value="seg_contour"/>
             <param name="thickness" value="2"/>
             <param name="color" value="#ff0000"/>
             <param name="show_label" value="--show_label"/>
-            <output name="out" value="test3.tif" ftype="tiff" compare="sim_size" delta_frac="0.1"/>
+            <expand macro="tests/intensity_image_diff" name="out_png" value="test3.png" ftype="png"/>
         </test>
-        <test>
-            <param name="im1" value="sample1.tif"/>
+        <test expect_num_outputs="1"><!-- segmentation overlay, 8bit test -->
+            <param name="im1" value="sample1_uint8.tif"/>
+            <param name="im2" value="mask2.tif"/>
+            <param name="method" value="seg_contour"/>
+            <param name="thickness" value="2"/>
+            <param name="color" value="#ff0000"/>
+            <expand macro="tests/intensity_image_diff" name="out_png" value="test4.png" ftype="png"/>
+        </test>
+        <test expect_num_outputs="1"><!-- segmentation overlay, 16bit test -->
+            <param name="im1" value="sample1_uint16.tif"/>
             <param name="im2" value="mask2.tif"/>
             <param name="method" value="seg_contour"/>
             <param name="thickness" value="2"/>
             <param name="color" value="#ff0000"/>
-            <output name="out" value="test4.tif" ftype="tiff" compare="sim_size" delta_frac="0.1"/>
+            <expand macro="tests/intensity_image_diff" name="out_png" value="test4.png" ftype="png" eps="1"/>
+        </test>
+        <test expect_num_outputs="1"><!-- segmentation overlay, 8bit RGB test -->
+            <param name="im1" value="sample1_uint8_rgb.png"/>
+            <param name="im2" value="mask2.tif"/>
+            <param name="method" value="seg_contour"/>
+            <param name="thickness" value="2"/>
+            <param name="color" value="#ff0000"/>
+            <expand macro="tests/intensity_image_diff" name="out_png" value="test5.png" ftype="png"/>
         </test>
     </tests>
-    <help>
-    **What it does**
+    <help><![CDATA[
+
+        **Overlays two images for visualization.**
 
-    This tool overlays two image to visualize 1) image blending, 2) colocalization, or 3) a segmentation mask over an image.
-    </help>
+        This tool overlays two image to visualize *linear image blending*, *colocalization*, or *segmentation contours*
+        over an intensity image. For *image blending* and *colocalization*, the input images must be single-channel 2-D
+        images. For *segmentation contours*, the intensity must be a 2-D single-channel or 2-D RGB image.
+
+    ]]></help>
     <citations>
         <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
     </citations>
Binary file test-data/sample1.tif has changed
Binary file test-data/sample1_uint16.tif has changed
Binary file test-data/sample1_uint8.tif has changed
Binary file test-data/sample1_uint8_rgb.png has changed
Binary file test-data/test3.png has changed
Binary file test-data/test3.tif has changed
Binary file test-data/test4.png has changed
Binary file test-data/test4.tif has changed
Binary file test-data/test5.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests.xml	Mon Sep 23 10:26:14 2024 +0000
@@ -0,0 +1,95 @@
+<macros>
+
+    <!-- Macros for verification of image outputs -->
+
+    <xml
+        name="tests/binary_image_diff"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="mae"
+        token_eps="0.01">
+
+        <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0">
+            <assert_contents>
+                <has_image_n_labels n="2"/>
+                <yield/>
+            </assert_contents>
+        </output>
+
+    </xml>
+
+    <xml
+        name="tests/label_image_diff"
+        tokens="name,value,ftype,metric,eps,pin_labels"
+        token_metric="iou"
+        token_eps="0.01"
+        token_pin_labels="0">
+
+        <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </output>
+
+    </xml>
+
+    <xml
+        name="tests/intensity_image_diff"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="rms"
+        token_eps="0.01">
+
+        <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </output>
+
+    </xml>
+
+    <!-- Variants of the above for verification of collection elements -->
+
+    <xml
+        name="tests/binary_image_diff/element"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="mae"
+        token_eps="0.01">
+
+        <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0">
+            <assert_contents>
+                <has_image_n_labels n="2"/>
+                <yield/>
+            </assert_contents>
+        </element>
+
+    </xml>
+
+    <xml
+        name="tests/label_image_diff/element"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="iou"
+        token_eps="0.01"
+        token_pin_labels="0">
+
+        <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </element>
+
+    </xml>
+
+    <xml
+        name="tests/intensity_image_diff/element"
+        tokens="name,value,ftype,metric,eps"
+        token_metric="rms"
+        token_eps="0.01">
+
+        <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@">
+            <assert_contents>
+                <yield/>
+            </assert_contents>
+        </element>
+
+    </xml>
+
+</macros>