changeset 0:732d95b2b030 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
author thomaswollmann
date Wed, 12 Dec 2018 04:38:34 -0500
parents
children
files labelimage2points.py labelimage2points.xml test-data/label.tif test-data/points.csv
diffstat 4 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/labelimage2points.py	Wed Dec 12 04:38:34 2018 -0500
@@ -0,0 +1,48 @@
+import argparse
+import sys
+import pandas as pd
+import skimage.io
+from skimage.measure import label
+from skimage.data import checkerboard
+import numpy as np
+
+
+
+def labelimage2points(input_file):
+    img_in = skimage.io.imread(input_file) 
+        
+    #amount of regions
+    amount_label = np.max(img_in)
+    
+    # iterate over all regions in order to calc center of mass
+    center_mass = []
+    for i in range(1,amount_label+1):    
+        #get coordinates of region
+        coord = np.where(img_in==i)
+        # be carefull with x,y coordinates
+        center_mass.append([np.mean(coord[1]),np.mean(coord[0])])
+
+    #make data frame of detections
+    out_dataFrame = pd.DataFrame(center_mass)
+
+
+    #return
+    return(out_dataFrame)
+
+    
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('input_file', help='input file')
+    parser.add_argument('out_file', help='out file (CSV)')
+    
+    args        = parser.parse_args()
+    input_file  = args.input_file
+    out_file    = args.out_file
+    
+    #TOOL
+    out_dataFrame = labelimage2points(input_file)
+    
+    #Print to csv file
+    out_dataFrame.to_csv(out_file,index=False,header=False)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/labelimage2points.xml	Wed Dec 12 04:38:34 2018 -0500
@@ -0,0 +1,28 @@
+<tool id="labelimage2points" name="Label 2 Points" version="0.1">
+    <description>Converts label image to points.</description>
+    <requirements>
+        <requirement type="package" version="0.12.3" >scikit-image</requirement>
+        <requirement type="package" version="0.21.0" >pandas</requirement>
+    </requirements>
+    <command>
+        <![CDATA[
+        python '$__tool_directory__/labelimage2points.py' '$input' '$output'
+        ]]>
+    </command>
+    <inputs>
+        <param name="input" type="data" format="tiff,png,jpg,bmp" label="Label image file"/>
+    </inputs>
+    <outputs>
+        <data format="csv" name="output"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="input" value="label.tif" />
+            <output name="output" value="points.csv" ftype="csv" />
+        </test>
+    </tests>
+    <help>Calculates the center of mass for all differently colored regions in the image.</help>
+    <citations>
+        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
+    </citations>
+</tool> 
Binary file test-data/label.tif has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/points.csv	Wed Dec 12 04:38:34 2018 -0500
@@ -0,0 +1,1 @@
+16.0,19.5