# HG changeset patch # User imgteam # Date 1549978545 18000 # Node ID a71239f3543a1c74533ec0e5e9064364e0a1853b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5 diff -r 000000000000 -r a71239f3543a landmark_registration.py --- /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) diff -r 000000000000 -r a71239f3543a landmark_registration.xml --- /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 @@ + + Landmark Registration + + scikit-image + pandas + numpy + + + + + + + + + + + + + + + + + + + + + + **What it does** + + This tool estimates the transformation matrix between two sets of 2d points. + + + 10.1016/j.jbiotec.2017.07.019 + + diff -r 000000000000 -r a71239f3543a test-data/points1.tsv --- /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 diff -r 000000000000 -r a71239f3543a test-data/points2.tsv --- /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 diff -r 000000000000 -r a71239f3543a test-data/warp.tsv --- /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