changeset 0:07ac39c0e949 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/\mergeneighboursinlabelimage commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:38:38 -0500
parents
children c6a6ab7c9940
files mergeneighboursinlabelimage.py mergeneighboursinlabelimage.xml test-data/galaxyIcon_noText.tif test-data/out.tiff
diffstat 4 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mergeneighboursinlabelimage.py	Sat Feb 09 14:38:38 2019 -0500
@@ -0,0 +1,48 @@
+import argparse
+import sys
+import skimage.io
+import skimage.util
+from skimage.measure import regionprops
+import scipy.spatial.distance
+import numpy as np
+import warnings
+
+def merge_n(img, dist=50):
+    props = regionprops(img)
+    found = False
+    for i in range(0, len(props)):
+        i_coords = props[i].coords
+        for q in range(0, len(props)):
+            if i==q:
+                continue
+            q_coords = props[q].coords
+            iq_dist = np.min(scipy.spatial.distance.cdist(i_coords, q_coords, 'euclidean'))
+            if iq_dist <= dist:
+                props[q].label = props[i].label
+                for a_point in range(0, q_coords.shape[0]):
+                    img[q_coords[a_point, 0], q_coords[a_point, 1]] = props[i].label
+                found = True
+    if found:
+        merge_n(img, dist)
+    return img
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
+    parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
+    parser.add_argument(
+        '-c',
+        dest='cluster_merge',
+        type=int,
+        required=False,
+        default=50,
+        help='Distance in pixel of clusters which are merged',
+    )
+    args = parser.parse_args()
+
+    label_image = skimage.io.imread(args.input_file.name)
+    label_image = merge_n(label_image, args.cluster_merge)
+    with warnings.catch_warnings():
+    	warnings.simplefilter("ignore")
+    	res = skimage.util.img_as_uint(label_image)
+    	skimage.io.imsave(args.out_file.name, res, plugin="tifffile")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mergeneighboursinlabelimage.xml	Sat Feb 09 14:38:38 2019 -0500
@@ -0,0 +1,34 @@
+<tool id="ip_merge_neighbours_in_label" name="Merge Neighbours in Label" version="0.2">
+    <description>Merge Neighbours in Label Image</description>
+    <requirements>
+        <requirement type="package" version="0.14.2">scikit-image</requirement>
+        <requirement type="package" version="1.15.4">numpy</requirement>
+    </requirements>
+    <command>
+        <![CDATA[
+        python '$__tool_directory__/mergeneighboursinlabelimage.py' '$input' ./tmp.tiff -c $c
+        ]]>
+    </command>
+    <inputs>
+        <param name="input" type="data" format="tiff,png,jpg,bmp" label="Label Image File"/>
+        <param  label="Distance in pixel of objects which are merged" name="c" type="integer" value="50"/>
+    </inputs>
+    <outputs>
+        <data format="tiff" name="output" from_work_dir="tmp.tiff"/>
+    </outputs>
+    <tests>
+        <test>
+          <param name="input" value="galaxyIcon_noText.tif"/>
+          <param name="c" value="10"/>
+          <output name="output" file="out.tiff" ftype="tiff" compare="sim_size"/>
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tools merges nearby objects in a label image using the minimum pixel distance.
+    </help>
+    <citations>
+        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
+    </citations>
+</tool>
Binary file test-data/galaxyIcon_noText.tif has changed
Binary file test-data/out.tiff has changed