changeset 0:a71239f3543a draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
author imgteam
date Tue, 12 Feb 2019 08:35:45 -0500
parents
children b0503eec7bd6
files landmark_registration.py landmark_registration.xml test-data/points1.tsv test-data/points2.tsv test-data/warp.tsv
diffstat 5 files changed, 80 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/landmark_registration.py	Tue Feb 12 08:35:45 2019 -0500
@@ -0,0 +1,27 @@
+from skimage.measure import ransac
+from skimage.transform import AffineTransform
+import pandas as pd
+import numpy as np
+import argparse
+
+def landmark_registration(points_file1, points_file2, out_file, residual_threshold=2, max_trials=100, delimiter="\t"):
+    points1 = pd.read_csv(points_file1, delimiter=delimiter)
+    points2 = pd.read_csv(points_file2, delimiter=delimiter)
+
+    src = np.concatenate([np.array(points1['x']).reshape([-1,1]), np.array(points1['y']).reshape([-1,1])], axis=-1)
+    dst = np.concatenate([np.array(points2['x']).reshape([-1,1]), np.array(points2['y']).reshape([-1,1])], axis=-1)
+
+    model = AffineTransform()
+    model_robust, inliers = ransac((src, dst), AffineTransform, min_samples=3,
+                                   residual_threshold=residual_threshold, max_trials=max_trials)
+    pd.DataFrame(model_robust.params).to_csv(out_file, header = None, index = False)
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Estimate transformation from points")
+    parser.add_argument("points_file1", help="Paste path to src points")
+    parser.add_argument("points_file2", help="Paste path to dst points")
+    parser.add_argument("warp_matrix", help="Paste path to warp_matrix.csv that should be used for transformation")
+    parser.add_argument("--residual_threshold", dest="residual_threshold", help="Maximum distance for a data point to be classified as an inlier.", type=float, default=2)
+    parser.add_argument("--max_trials", dest="max_trials", help="Maximum number of iterations for random sample selection.", type=int, default=100)
+    args = parser.parse_args()
+    landmark_registration(args.points_file1, args.points_file2, args.warp_matrix, residual_threshold=args.residual_threshold, max_trials=args.max_trials)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/landmark_registration.xml	Tue Feb 12 08:35:45 2019 -0500
@@ -0,0 +1,42 @@
+<tool id="ip_landmark_registration" name="Landmark Registration" version="0.0.2">
+    <description>Landmark Registration</description>
+    <requirements>
+        <requirement type="package" version="0.14.2">scikit-image</requirement>
+        <requirement type="package" version="0.23.4">pandas</requirement>
+        <requirement type="package" version="1.15.4">numpy</requirement>
+    </requirements>
+    <command><![CDATA[
+         python '$__tool_directory__/landmark_registration.py'
+         --residual_threshold $residual_threshold
+         --max_trials $max_trials
+         '$points_file1'
+         '$points_file2'
+         '$warp_matrix'
+]]></command>
+    <inputs>
+          <param name="points_file1" type="data" format="tabular" label="Path to tab-separated file with src points" />
+          <param name="points_file2" type="data" format="tabular" label="Path to tab-separated file with dst points" />
+          <param name="residual_threshold" type="float" value="2" label="Maximum distance for a data point to be classified as an inlier." />
+        <param name="max_trials" type="integer" value="100" label="Maximum number of iterations for random sample selection." />
+    </inputs>
+    <outputs>
+       <data format="tabular" name="warp_matrix" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="points_file1" value="points1.tsv"/>
+            <param name="points_file2" value="points2.tsv"/>
+            <param name="residual_threshold" value="2"/>
+            <param name="max_trials" value="100"/>
+            <output name="warp_matrix" value="warp.tsv" ftype="tabular" compare="diff" lines_diff="6"/>
+        </test>
+    </tests>
+    <help>
+    **What it does**
+
+    This tool estimates the transformation matrix between two sets of 2d points.
+    </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/points1.tsv	Tue Feb 12 08:35:45 2019 -0500
@@ -0,0 +1,4 @@
+	x	y
+0	1	6
+1	5	2
+2	13	15
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/points2.tsv	Tue Feb 12 08:35:45 2019 -0500
@@ -0,0 +1,4 @@
+	x	y
+0	3	5
+1	7	1
+2	15	14
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/warp.tsv	Tue Feb 12 08:35:45 2019 -0500
@@ -0,0 +1,3 @@
+1.0000000000000002	-7.211110073938364e-17	1.9999999999999973
+7.211110073938364e-17	0.9999999999999999	-0.9999999999999973
+0.0	0.0	1.0