From 0f5d6153d24ca7cbe5dda1a1bac991cf862a566a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 22 Jul 2012 08:58:37 +0200 Subject: [PATCH] fix bug in estimation of similarity transformation --- skimage/transform/_geometric.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index fe829109..70584664 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -271,6 +271,40 @@ class SimilarityTransform(AffineTransform): shear=0, translation=translation) + def estimate(self, src, dst): + """Set the transformation matrix with the explicit transformation + parameters. + + Parameters + ---------- + src : Nx2 array + source coordinates + dst : Nx2 array + destination coordinates + + """ + xs = src[:, 0] + ys = src[:, 1] + xd = dst[:, 0] + yd = dst[:, 1] + rows = src.shape[0] + + #: params: a0, a1, b0, b1 + A = np.zeros((rows * 2, 4)) + A[:rows, 0] = xs + A[:rows, 2] = - ys + A[:rows, 1] = 1 + A[rows:, 2] = xs + A[rows:, 0] = ys + A[rows:, 3] = 1 + + b = np.hstack([xd, yd]) + + a0, a1, b0, b1 = np.linalg.lstsq(A, b)[0] + self._matrix = np.array([[a0, -b0, a1], + [b0, a0, b1], + [ 0, 0, 1]]) + class PolynomialTransform(GeometricTransform): """2D transformation of the form::