changeset 0:629d9e8ca64c draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
author thomaswollmann
date Wed, 12 Dec 2018 04:37:59 -0500
parents
children ff66bae1f7f8
files detection_viz.py detection_viz.xml test-data/out.png test-data/out.tif test-data/sample.png
diffstat 5 files changed, 93 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/detection_viz.py	Wed Dec 12 04:37:59 2018 -0500
@@ -0,0 +1,60 @@
+import argparse
+import sys
+import os
+import csv
+
+import matplotlib
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
+
+import skimage.io
+
+def plot_circles(file_name, ax, color, stroke_size, radius):
+    resfile = open(file_name, 'rb')
+    rd = csv.reader(resfile, delimiter=',')
+    for row in rd:
+        circ = plt.Circle((int(row[1]), int(row[0])), lw=stroke_size, radius=radius, color=color, fill=False)
+        ax.add_patch(circ)
+    resfile.close()
+
+def detection_viz(input_file, output_file, tp=None, fn=None, fp=None, stroke_size=3, circle_radius=50):
+    img = skimage.io.imread(input_file)
+
+    fig = plt.figure(figsize=(40, 40))
+    ax = fig.add_axes([0, 0, 1, 1])
+    ax.axis('off')
+
+    plt.imshow(img)
+    if tp is not None:
+        plot_circles(tp, ax, '#00FF00', stroke_size, circle_radius)
+    if fn is not None:
+        plot_circles(fn, ax, 'red', stroke_size, circle_radius)
+    if fp is not None:
+        plot_circles(fp, ax, 'darkorange', stroke_size, circle_radius)
+
+    fig.canvas.print_png("tmp.png", dpi=1800)
+    os.rename("tmp.png", output_file)
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('input_file', type=argparse.FileType('r'), help='original file')
+    # output file should not be of type argparse.FileType('w') sine it is created immediately in this case which leads to an error in renaming
+    parser.add_argument('out_file_str', type=str, help='string of output file name') 
+    parser.add_argument('--tp', dest='input_tp_file', type=argparse.FileType('r'), help='input TP file')
+    parser.add_argument('--fn', dest='input_fn_file', type=argparse.FileType('r'), help='input FN file')
+    parser.add_argument('--fp', dest='input_fp_file', type=argparse.FileType('r'), help='input FP file')
+    parser.add_argument('--stroke_size', dest='thickness', default=3, type=float, help='stroke thickness')
+    parser.add_argument('--circle_radius', dest='circle_radius', type=float, default=50, help='circle radius')
+    args = parser.parse_args()
+
+    tp=None
+    if args.input_tp_file:
+        tp=args.input_tp_file.name
+    fn=None
+    if args.input_fn_file:
+        fn=args.input_fn_file.name
+    fp=None
+    if args.input_fp_file:
+        fp=args.input_fp_file.name
+
+    detection_viz(args.input_file.name, args.out_file_str, tp=tp, fn=fn, fp=fp, stroke_size=args.thickness, circle_radius=args.circle_radius)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/detection_viz.xml	Wed Dec 12 04:37:59 2018 -0500
@@ -0,0 +1,33 @@
+<tool id="detection_viz" name="Detection Visualization" version="0.1">
+    <description>Detection Visualization</description>
+    <requirements>
+      <requirement type="package" version="0.14.1" >scikit-image</requirement>
+      <requirement type="package" version="3.0.2" >matplotlib</requirement>
+    </requirements>
+    <command>
+        <![CDATA[
+        python '$__tool_directory__/detection_viz.py' '$input' '$output' --stroke_size $thickness --circle_radius $circle_radius $tp $fn $fp
+]]>
+    </command>
+    <inputs>
+        <param name="input" type="data" format="tiff,png,jpg,bmp" label="Binary Image File"/>
+        <param name="tp" type="boolean" checked="false" falsevalue="" truevalue="--tp"/>
+        <param name="fn" type="boolean" checked="false" falsevalue="" truevalue="--fn"/>
+        <param name="fp" type="boolean" checked="false" falsevalue="" truevalue="--fp"/>
+        <param name="thickness" type="float" value="3.0" label="Stroke thickness"/>
+        <param name="circle_radius" type="float" value="50.0" label="Circle radius"/>
+    </inputs>
+    <outputs>
+        <data format="png" name="output"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="input" value="sample.png"/>
+            <output name="output" value="out.png" ftype="png"/>
+        </test>
+    </tests>
+    <help>Draws circles of different colors around detected true positives, false negatives and false positives.</help>
+    <citations>
+        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
+    </citations>
+</tool> 
Binary file test-data/out.png has changed
Binary file test-data/out.tif has changed
Binary file test-data/sample.png has changed