mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-11 12:43:04 +08:00
Speed up transformation of piecewise-affine
This commit is contained in:
@@ -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):
|
simplex = self.tesselation.find_simplex(coords)
|
||||||
# determine which triangle contains the point
|
|
||||||
simplex_index = self.tesselation.find_simplex(pt)
|
|
||||||
|
|
||||||
if simplex_index == - 1:
|
out[simplex == -1, :] = -1
|
||||||
# this point is outside the hull of the control points
|
|
||||||
out[index, 0] = - 1
|
|
||||||
out[index, 1] = - 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
# calculate affine transformed position
|
for index in range(len(self.tesselation.vertices)):
|
||||||
affine = self.affines[simplex_index]
|
# affine transform for triangle
|
||||||
dst_pos = affine(pt)
|
affine = self.affines[index]
|
||||||
out[index, 0] = dst_pos[0][0]
|
# all coordinates within triangle
|
||||||
out[index, 1] = dst_pos[0][1]
|
index_mask = simplex == index
|
||||||
|
|
||||||
|
out[index_mask, :] = affine(coords[index_mask, :])
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user