changeset 0:1117551218d6 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:16:09 -0500
parents
children db2a47e0089f
files coordinates_of_roi.py coordinates_of_roi.xml test-data/table.tsv test-data/table2.tsv test-data/test.png
diffstat 5 files changed, 104 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coordinates_of_roi.py	Sat Feb 09 14:16:09 2019 -0500
@@ -0,0 +1,40 @@
+import argparse
+import pandas as pd
+import skimage.io
+import skimage.color
+import warnings
+
+def get_pixel_values(im, pixel_table, white_obj, threshold, offset=[0,0]):
+    data = skimage.io.imread(im)
+    if len(data.shape) == 3 and data.shape[-1] > 1:
+        data = skimage.color.rgb2grey(data)
+    x = []
+    y = []
+    for i in range(data.shape[0]):
+        for j in range(data.shape[1]):
+            if white_obj == False:
+                if data[i,j] <= threshold:
+                    x.append(j + offset[0])
+                    y.append(i + offset[1])
+            elif data[i,j] >= threshold:
+                    x.append(j + offset[0])
+                    y.append(i + offset[1])
+                    
+    df = pd.DataFrame()
+    df['x'] = x
+    df['y'] = y
+    df.to_csv(pixel_table, sep="\t", index = False)
+                     
+if __name__=="__main__":
+    parser = argparse.ArgumentParser(description = "Create a csv table with Coordinates of the ROI")
+    parser.add_argument("im", help = "Paste path to out.png (output created by transformation)")
+    parser.add_argument("pixel_table", help = "Paste path to file in which list with all pixles > threshold should be saved")
+    parser.add_argument('offset_x', type=int, help='offset in x direction (width)', default=0)
+    parser.add_argument('offset_y', type=int, help='offset in y direction (height)', default=0)
+    parser.add_argument("--white_obj", dest = "white_obj", default=False, help = "If set objects in image are white otherwise black", action = "store_true")
+    parser.add_argument("--threshold", dest = "threshold", default = 0.5, help = "Enter desired threshold value", type = float)
+    
+    args = parser.parse_args()  
+    # with warnings.catch_warnings():
+	#     warnings.simplefilter("ignore") 
+    get_pixel_values(args.im, args.pixel_table, args.white_obj, args.threshold, [args.offset_x, args.offset_y])     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coordinates_of_roi.xml	Sat Feb 09 14:16:09 2019 -0500
@@ -0,0 +1,50 @@
+<tool id="ip_coordinates_of_roi" name="Coordinates of ROI" version="0.0.3">
+    <description></description>
+    <requirements>
+        <requirement type="package" version="0.14.2">scikit-image</requirement>
+        <requirement type="package" version="0.23.4">pandas</requirement>
+    </requirements>
+    <command detect_errors="aggressive">
+        <![CDATA[
+            python '$__tool_directory__/coordinates_of_roi.py'
+            '$im'
+            '$pixel_table'
+            $offset_x $offset_y
+            $white_obj
+            --threshold $threshold
+        ]]>
+    </command>
+    <inputs>
+        <param name="im" type="data" format="png" label="Source file" />
+        <param name="white_obj" type="boolean" truevalue="--white_obj" falsevalue="" checked="false"
+            label="Set to Yes if object is white and background black, otherwise set to No" />
+        <param name="threshold" type="float" value="0.5" label="Threshold value" />
+        <param name="offset_x" type="integer" value="0" label="Added offset in x direction (=width direction)" />
+        <param name="offset_y" type="integer" value="0" label="Added offset in y direction (=height direction)" />
+    </inputs>
+    <outputs>
+       <data format="tabular" name="pixel_table" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="im" value="test.png"/>
+            <param name="white_obj" value="true"/>
+            <output name="pixel_table" value="table.tsv" ftype="tabular"/>
+        </test>
+        <test>
+            <param name="im" value="test.png"/>
+            <param name="white_obj" value="true"/>
+            <param name="offset_x" value="1"/>
+            <param name="offset_y" value="2"/>
+            <output name="pixel_table" value="table2.tsv" ftype="tabular"/>
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tool creates a table containing the pixelcoordinates of the Region of Interest (ROI).
+    </help>
+    <citations>
+        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/table.tsv	Sat Feb 09 14:16:09 2019 -0500
@@ -0,0 +1,7 @@
+x	y
+4	5
+5	5
+6	5
+7	5
+8	5
+9	5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/table2.tsv	Sat Feb 09 14:16:09 2019 -0500
@@ -0,0 +1,7 @@
+x	y
+5	7
+6	7
+7	7
+8	7
+9	7
+10	7
Binary file test-data/test.png has changed