From 5dbb6e325795aef4c160962f09fe64d8989069a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 24 Dec 2014 15:27:10 +0100 Subject: [PATCH] Improve conditioning of silimarity transform design matrix --- skimage/transform/_geometric.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index ca8f6329..22a09980 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -651,6 +651,10 @@ class SimilarityTransform(ProjectiveTransform): Destination coordinates. """ + + src_matrix, src = _center_and_normalize_points(src) + dst_matrix, dst = _center_and_normalize_points(dst) + xs = src[:, 0] ys = src[:, 1] xd = dst[:, 0] @@ -674,9 +678,15 @@ class SimilarityTransform(ProjectiveTransform): # singular value a0, a1, b0, b1 = - V[-1, :-1] / V[-1, -1] - self.params = np.array([[a0, -b0, a1], - [b0, a0, b1], - [ 0, 0, 1]]) + S = np.array([[a0, -b0, a1], + [b0, a0, b1], + [ 0, 0, 1]]) + + # De-center and de-normalize + S = np.dot(np.linalg.inv(dst_matrix), np.dot(S, src_matrix)) + + self.params = S + @property def scale(self):