From c1f3515e0065e5aa2af51def5d5300a4aafef8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 3 Sep 2012 21:29:19 +0200 Subject: [PATCH] Speed up transformation of piecewise-affine --- skimage/transform/_geometric.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 54764742..6d64ec5c 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -361,23 +361,19 @@ class PiecewiseAffineTransform(ProjectiveTransform): """ - out = - 1 * np.ones((coords.shape[0], 2)) + out = np.empty_like(coords) - for index, pt in enumerate(coords): - # determine which triangle contains the point - simplex_index = self.tesselation.find_simplex(pt) + simplex = self.tesselation.find_simplex(coords) - if simplex_index == - 1: - # this point is outside the hull of the control points - out[index, 0] = - 1 - out[index, 1] = - 1 - continue + out[simplex == -1, :] = -1 - # calculate affine transformed position - affine = self.affines[simplex_index] - dst_pos = affine(pt) - out[index, 0] = dst_pos[0][0] - out[index, 1] = dst_pos[0][1] + for index in range(len(self.tesselation.vertices)): + # affine transform for triangle + affine = self.affines[index] + # all coordinates within triangle + index_mask = simplex == index + + out[index_mask, :] = affine(coords[index_mask, :]) return out