Mercurial > repos > imgteam > landmark_registration
comparison landmark_registration.py @ 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a71239f3543a |
---|---|
1 from skimage.measure import ransac | |
2 from skimage.transform import AffineTransform | |
3 import pandas as pd | |
4 import numpy as np | |
5 import argparse | |
6 | |
7 def landmark_registration(points_file1, points_file2, out_file, residual_threshold=2, max_trials=100, delimiter="\t"): | |
8 points1 = pd.read_csv(points_file1, delimiter=delimiter) | |
9 points2 = pd.read_csv(points_file2, delimiter=delimiter) | |
10 | |
11 src = np.concatenate([np.array(points1['x']).reshape([-1,1]), np.array(points1['y']).reshape([-1,1])], axis=-1) | |
12 dst = np.concatenate([np.array(points2['x']).reshape([-1,1]), np.array(points2['y']).reshape([-1,1])], axis=-1) | |
13 | |
14 model = AffineTransform() | |
15 model_robust, inliers = ransac((src, dst), AffineTransform, min_samples=3, | |
16 residual_threshold=residual_threshold, max_trials=max_trials) | |
17 pd.DataFrame(model_robust.params).to_csv(out_file, header = None, index = False) | |
18 | |
19 if __name__ == "__main__": | |
20 parser = argparse.ArgumentParser(description="Estimate transformation from points") | |
21 parser.add_argument("points_file1", help="Paste path to src points") | |
22 parser.add_argument("points_file2", help="Paste path to dst points") | |
23 parser.add_argument("warp_matrix", help="Paste path to warp_matrix.csv that should be used for transformation") | |
24 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) | |
25 parser.add_argument("--max_trials", dest="max_trials", help="Maximum number of iterations for random sample selection.", type=int, default=100) | |
26 args = parser.parse_args() | |
27 landmark_registration(args.points_file1, args.points_file2, args.warp_matrix, residual_threshold=args.residual_threshold, max_trials=args.max_trials) |