changeset 4:984358e43242 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 00199464fa2aa1928a49e2379edf199c3db91533
author imgteam
date Tue, 14 Nov 2023 08:27:27 +0000
parents 9bb446db4a1e
children
files 2d_split_binaryimage_by_watershed.py binary2label.xml test-data/in.tif test-data/out.tif
diffstat 4 files changed, 67 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2d_split_binaryimage_by_watershed.py	Tue Nov 14 08:27:27 2023 +0000
@@ -0,0 +1,28 @@
+import argparse
+import sys
+
+import skimage.io
+import skimage.util
+from scipy import ndimage as ndi
+from skimage.feature import peak_local_max
+from skimage.morphology import watershed
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description='Split binaryimage by watershed')
+    parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
+    parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
+    parser.add_argument('min_distance', type=int, default=100, help='Minimum distance to next object')
+    args = parser.parse_args()
+
+    img_in = skimage.io.imread(args.input_file.name)
+    distance = ndi.distance_transform_edt(img_in)
+    local_maxi = peak_local_max(distance,
+                                indices=False,
+                                min_distance=args.min_distance,
+                                labels=img_in)
+    markers = ndi.label(local_maxi)[0]
+    res = watershed(-distance, markers, mask=img_in)
+
+    res = skimage.util.img_as_uint(res)
+    skimage.io.imsave(args.out_file.name, res, plugin="tifffile")
--- a/binary2label.xml	Mon Nov 13 22:10:33 2023 +0000
+++ b/binary2label.xml	Tue Nov 14 08:27:27 2023 +0000
@@ -1,5 +1,9 @@
-<tool id="ip_binary_to_labelimage" name="Convert binary image to label map" version="0.4-2"> 
+<tool id="ip_binary_to_labelimage" name="Convert binary image to label map" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@"> 
     <description></description>
+    <macros>
+        <token name="@TOOL_VERSION@">0.5</token>
+        <token name="@VERSION_SUFFIX@">0</token>
+    </macros>
     <edam_operations>
         <edam_operation>operation_3443</edam_operation>
     </edam_operations>
@@ -7,16 +11,34 @@
         <xref type="bio.tools">galaxy_image_analysis</xref>
     </xrefs>
     <requirements>
-        <requirement type="package" version="0.12.3">scikit-image</requirement> 
+        <requirement type="package" version="0.14.2">scikit-image</requirement> 
         <requirement type="package" version="0.15.1">tifffile</requirement>
+        <requirement type="package" version="1.15.4">numpy</requirement>
+        <requirement type="package" version="5.3.0">pillow</requirement>
+        <requirement type="package" version="1.2.1">scipy</requirement>
     </requirements>
     <command detect_errors="aggressive">
         <![CDATA[
-        python '$__tool_directory__/binary2label.py' '$input' '$output'
+        #if str($mode.mode_selector) == 'cca':
+            python '$__tool_directory__/binary2label.py' '$input' '$output'
+        #elif str($mode.mode_selector) == 'watershed':
+            python '$__tool_directory__/2d_split_binaryimage_by_watershed.py' '$input' '$output' $min_distance
+        #end if
         ]]>
     </command>
     <inputs>
-        <param name="input" type="data" format="tiff,png,jpg,bmp" label="Binary Image File"/>
+        <param name="input" type="data" format="tiff,png,jpg,bmp" label="Binary image"/>
+        <conditional name="mode">
+            <param name="mode_selector" type="select" label="Mode">
+                <option value="cca">Connected component analysis</option>
+                <option value="watershed">Watershed transform</option>
+            </param>
+            <when value="cca">
+            </when>
+            <when value="watershed">
+                <param name="min_distance" type="integer" min="0" value="5" label="Minimum distance between two objects" />
+            </when>
+        </conditional>
     </inputs>
     <outputs>
         <data format="tiff" name="output"/>
@@ -24,13 +46,24 @@
     <tests>
         <test>
             <param name="input" value="galaxyIcon_noText.tif" />
+            <conditional name="mode">
+                <param name="mode_selector" value="cca" />
+            </conditional>
             <output name="output" value="label.tif" ftype="tiff" compare="sim_size"/>
         </test>
+        <test>
+            <param name="input" value="in.tif"/>
+            <conditional name="mode">
+                <param name="mode_selector" value="watershed" />
+                <param name="min_distance" value="10" />
+            </conditional>
+            <output name="output" value="out.tif" ftype="tiff" compare="sim_size"/>
+        </test>
     </tests>
     <help>
-    **What it does**
+    This tool assigns each object a unique label.
 
-    This tool assigns every object an own grey value.
+    Individual objects are determined using connected component analysis, or distance transform and watershed.
     </help>
     <citations>
         <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
Binary file test-data/in.tif has changed
Binary file test-data/out.tif has changed