annotate landmark_registration.py @ 4:aee73493bf53 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
author imgteam
date Mon, 18 Jul 2022 18:41:19 +0000
parents 4e089a0983b1
children 12997d4c5b00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
1 """
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
2 Copyright 2017-2022 Biomedical Computer Vision Group, Heidelberg University.
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
3
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
4 Distributed under the MIT license.
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
6
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
7 """
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
8
0
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
9 import argparse
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
10
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
11 import numpy as np
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
12 import pandas as pd
4
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
13 from scipy import spatial
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
14 from scipy.linalg import lstsq
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
15 from skimage.measure import ransac
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
16 from skimage.transform import AffineTransform
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
17
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
18
4
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
19 class pwlTransform(object):
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
20
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
21 def __init__(self):
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
22 self.triangulation = None
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
23 self.affines = None
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
24
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
25 def estimate(self, src, dst):
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
26 self.triangulation = spatial.Delaunay(src)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
27 success = True
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
28 self.affines = []
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
29 for tri in self.triangulation.simplices:
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
30 affine = AffineTransform()
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
31 success &= affine.estimate(src[tri, :], dst[tri, :])
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
32 self.affines.append(affine)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
33 return success
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
34
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
35 def __call__(self, coords):
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
36 simplex = self.triangulation.find_simplex(coords)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
37 simplex[simplex == -1] = 0 # todo: dealing with points outside the triangulation
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
38 out = np.empty_like(coords, np.float64)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
39 for i in range(len(self.triangulation.simplices)):
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
40 idx = simplex == i
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
41 out[idx, :] = self.affines[i](coords[idx, :])
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
42 return out
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
43
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
44
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
45 def landmark_registration(pts_f1, pts_f2, out_f, pts_f=None, res_th=None, max_ite=None, delimiter="\t"):
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
46
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
47 points1 = pd.read_csv(pts_f1, delimiter=delimiter)
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
48 points2 = pd.read_csv(pts_f2, delimiter=delimiter)
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
49
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
50 src = np.concatenate([np.array(points1['x']).reshape([-1, 1]),
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
51 np.array(points1['y']).reshape([-1, 1])],
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
52 axis=-1)
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
53 dst = np.concatenate([np.array(points2['x']).reshape([-1, 1]),
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
54 np.array(points2['y']).reshape([-1, 1])],
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
55 axis=-1)
0
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
56
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
57 if res_th is not None and max_ite is not None:
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
58 model_robust, inliers = ransac((src, dst), AffineTransform, min_samples=3, residual_threshold=res_th, max_trials=max_ite)
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
59 pd.DataFrame(model_robust.params).to_csv(out_f, header=None, index=False, sep="\t")
0
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
60
4
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
61 elif pts_f is not None:
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
62 pwlt = pwlTransform()
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
63 pwlt.estimate(src, dst)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
64
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
65 pts_df = pd.read_csv(pts_f, delimiter=delimiter)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
66 pts = np.concatenate([np.array(pts_df['x']).reshape([-1, 1]),
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
67 np.array(pts_df['y']).reshape([-1, 1])],
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
68 axis=-1)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
69 pts_pwlt = pwlt(pts)
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
70
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
71 df = pd.DataFrame()
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
72 df['x'] = pts_pwlt[:, 0]
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
73 df['y'] = pts_pwlt[:, 1]
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
74 df.to_csv(out_f, index=False, sep="\t", float_format='%.1f')
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
75
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
76 else:
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
77 A = np.zeros((src.size, 6))
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
78 A[0:src.shape[0], [0, 1]] = src
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
79 A[0:src.shape[0], 2] = 1
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
80 A[src.shape[0]:, [3, 4]] = src
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
81 A[src.shape[0]:, 5] = 1
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
82 b = dst.T.flatten().astype('float64')
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
83 x = lstsq(A, b)
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
84
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
85 tmat = np.eye(3)
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
86 tmat[0, :] = x[0].take([0, 1, 2])
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
87 tmat[1, :] = x[0].take([3, 4, 5])
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
88 pd.DataFrame(tmat).to_csv(out_f, header=None, index=False, sep="\t")
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
89
0
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
90
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
91 if __name__ == "__main__":
4
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
92 parser = argparse.ArgumentParser(description="estimates the affine transformation matrix or performs piecewiese affine transformation based on landmarks")
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
93 parser.add_argument("fn_lmkmov", help="Coordinates of moving landmarks (tsv file)")
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
94 parser.add_argument("fn_lmkfix", help="Coordinates of fixed landmarks (tsv file)")
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
95 parser.add_argument("fn_out", help="Path to the output")
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
96 parser.add_argument("--pwlt", dest="fn_ptsmov", help="Coordinates of points to be transformed (tsv file)")
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
97 parser.add_argument("--res_th", dest="res_th", type=float, help="Maximum distance for a data point to be classified as an inlier")
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
98 parser.add_argument("--max_ite", dest="max_ite", type=int, help="Maximum number of iterations for random sample selection")
0
a71239f3543a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff changeset
99 args = parser.parse_args()
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
100
4
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
101 fn_ptsmov = None
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
102 if args.fn_ptsmov:
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
103 fn_ptsmov = args.fn_ptsmov
2
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
104 res_th = None
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
105 if args.res_th:
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
106 res_th = args.res_th
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
107 max_ite = None
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
108 if args.max_ite:
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
109 max_ite = args.max_ite
4e089a0983b1 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit 927b78d47c31714776ccdf3d16f26c3779298abb"
imgteam
parents: 1
diff changeset
110
4
aee73493bf53 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit ba383a4f617791d0c84737a179e5b4b66cecc334
imgteam
parents: 2
diff changeset
111 landmark_registration(args.fn_lmkmov, args.fn_lmkfix, args.fn_out, pts_f=fn_ptsmov, res_th=res_th, max_ite=max_ite)