changeset 0:c983b2d2cdd7 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
author thomaswollmann
date Wed, 12 Dec 2018 04:49:24 -0500
parents
children
files binaryimage2points.py binaryimage2points.xml test-data/galaxyIcon_noText.tif test-data/points.csv
diffstat 4 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/binaryimage2points.py	Wed Dec 12 04:49:24 2018 -0500
@@ -0,0 +1,55 @@
+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
+import warnings 
+
+
+
+def binaryimage2points(input_file):
+    # ignore warnings that arise when importing a package that was compiled against an older version of numpy than installed; https://github.com/numpy/numpy/pull/432
+    warnings.filterwarnings("ignore") 
+
+    img_in = skimage.io.imread(input_file, plugin='tifffile') 
+    
+    #make label image
+    label = skimage.measure.label(img_in)
+    
+    #amount of regions
+    amount_label = np.max(label)
+    
+    # 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(label==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 = binaryimage2points(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/binaryimage2points.xml	Wed Dec 12 04:49:24 2018 -0500
@@ -0,0 +1,29 @@
+<tool id="binaryimage2points" name="Binary To Points" version="0.1">
+    <description>Converts Binary Image to Points</description>
+    <requirements>
+        <requirement type="package" version="1.15.4">numpy</requirement><!--https://github.com/numpy/numpy/pull/432 -->
+        <requirement type="package" version="0.14.0" >scikit-image</requirement>
+        <requirement type="package" version="0.23.4" >pandas</requirement>
+    </requirements>
+    <command>
+        <![CDATA[
+        python '$__tool_directory__/binaryimage2points.py' '$input' '$output'
+        ]]>
+    </command>
+    <inputs>
+        <param name="input" type="data" format="tiff" label="Binary Image File"/>
+    </inputs>
+    <outputs>
+        <data format="csv" name="output"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="input" value="galaxyIcon_noText.tif" />
+            <output name="output" value="points.csv" ftype="csv" />
+        </test>
+    </tests>
+    <help>This tool converts an image to points.</help>
+    <citations>
+        <citation type="doi">10.7717/peerj.453</citation>
+    </citations>
+</tool> 
Binary file test-data/galaxyIcon_noText.tif has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/points.csv	Wed Dec 12 04:49:24 2018 -0500
@@ -0,0 +1,1 @@
+11.755597014925373,10.404850746268657