changeset 0:63b2a10b1001 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:41:11 -0500
parents
children 8ad39f493587
files overlay_segmentation_mask.py overlay_segmentation_mask.xml test-data/outt.png test-data/sample.tif test-data/sample_seg.tif
diffstat 5 files changed, 100 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/overlay_segmentation_mask.py	Sat Feb 09 14:41:11 2019 -0500
@@ -0,0 +1,41 @@
+import argparse
+import sys
+import os
+
+import matplotlib
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
+
+#TODO make importable by python script
+
+import skimage.io
+import skimage.measure
+
+parser = argparse.ArgumentParser()
+parser.add_argument('input_file', type=argparse.FileType('r'), help='input file')
+parser.add_argument('mask_file', type=argparse.FileType('r'), help='mask file')
+parser.add_argument('out_file', type=str, help='out file (PNG)') # file would be created immediately with argparse.FileType('w') s.t. file cannot be renamed on galaxy
+parser.add_argument('--grey', dest='greyscale', action='store_true', help='image is greyscale')
+parser.add_argument('--label', dest='label', action='store_true', help='plot label')
+parser.add_argument('--label_color', dest='label_color', default='#FFFF00', help='label color')
+parser.add_argument('--thickness', dest='thickness', default=0.3, type=float, help='thickness')
+parser.add_argument('--stroke_color', dest='stroke_color', default='#ff0000', help='stroke color')
+args = parser.parse_args()
+img = skimage.io.imread(args.input_file.name)
+label = skimage.io.imread(args.mask_file.name)
+
+fig = plt.figure()
+ax = fig.add_axes([0, 0, 1, 1])
+ax.axis('off')
+
+if args.label:
+    for reg in skimage.measure.regionprops(label):
+        ax.text(reg.centroid[1], reg.centroid[0], str(reg.label), color=args.label_color)
+
+if args.greyscale:
+    plt.imshow(img, cmap=plt.cm.gray)
+else:
+    plt.imshow(img)
+plt.contour(label, linewidths=args.thickness, colors=args.stroke_color)
+
+fig.canvas.print_png(args.out_file)
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/overlay_segmentation_mask.xml	Sat Feb 09 14:41:11 2019 -0500
@@ -0,0 +1,59 @@
+<tool id="ip_overlay_segmentation" name="Overlay Segmentation Mask" version="0.0.6">
+    <description>Overlay Segmentation Mask</description>
+    <requirements>
+        <requirement type="package" version="0.14.2">scikit-image</requirement>
+        <requirement type="package" version="3.0.2">matplotlib</requirement>
+        <requirement type="package" version="5.3.0">pillow</requirement>
+        <requirement type="package" version="0.10.0">tifffile</requirement>
+    </requirements>
+    <command detect_errors="aggressive"><![CDATA[
+        python '$__tool_directory__/overlay_segmentation_mask.py'
+        $greyscale 
+        #if str($label_option.label) == '--label'
+            --label --label_color '$label_option.label_color'
+        #end if
+        --thickness $thickness
+        --stroke_color '$stroke_color'
+        '$input_image' '$input_mask' ./tmp.png
+       ]]>
+    </command>
+    <inputs>
+        <param name="input_image" type="data" label="Image Source File" format="tif,bmp,jpg,png"/>
+        <param name="input_mask" type="data" label="Mask Source File" format="tif,bmp,jpg,png"/>
+        <param name="greyscale" type="boolean" checked='true' truevalue='--grey' falsevalue='' label="Image Is Greyscale" />
+        <param name="thickness" size="4" type="float" value="0.3" label="Thickness" />
+        <param name="stroke_color" type="color" value="#ff0000" label="Stroke Color"/>
+        <conditional name="label_option">
+            <param name="label" type="boolean" checked='false' truevalue='--label' falsevalue='' label="Plot Labels" />
+            <when value=""> </when>
+            <when value="--label">
+                <param name="label_color" type="color" value="#ffff00" label="Label Color"/>
+            </when>
+        </conditional>
+    </inputs>
+    <outputs>
+        <data format="png" name="output" from_work_dir="tmp.png" />
+    </outputs>
+    <tests>
+        <test>
+            <conditional name="label_option">
+                <param name="label" value="--label"/>
+                <param name="label_color" value="#ffff00"/>
+            </conditional>
+            <param name="stroke_color" value="#ffaa00"/>
+            <param name="label_option['label']" value="--label"/>
+            <param name="input_image" value="sample.tif"/>
+            <param name="input_mask" value="sample_seg.tif"/>
+            <param name="greyscale" value="--grey"/> 
+            <output name="output" value="outt.png" ftype="png" compare="sim_size"/>
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tool overlays a segmentation mask over an image.
+    </help>
+    <citations>
+        <citation type="doi">10.7717/peerj.453</citation>
+    </citations>
+</tool>
Binary file test-data/outt.png has changed
Binary file test-data/sample.tif has changed
Binary file test-data/sample_seg.tif has changed