本文整理汇总了Python中scipy.spatial.Delaunay.close方法的典型用法代码示例。如果您正苦于以下问题:Python Delaunay.close方法的具体用法?Python Delaunay.close怎么用?Python Delaunay.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.spatial.Delaunay
的用法示例。
在下文中一共展示了Delaunay.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __warp
# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import close [as 别名]
def __warp(image, points, size):
"""
Warp an image using the provided point locations.
"""
rows, cols = size[:2]
# perform triangulation on the control points
delaunay = Delaunay(points)
triangles = delaunay.simplices
output = np.zeros((rows, cols, 3), np.uint8)
grid = np.vstack(np.unravel_index(xrange(0, rows*cols), size)).T
membership = delaunay.find_simplex(grid)
for triangle_id in range(len(triangles)):
triangle = triangles[triangle_id]
# Transformation matrix from output triangle to source triangle
src = np.vstack((image['points'][triangle, :].T, [1, 1, 1]))
dst = np.vstack((points[triangle, :].T, [1, 1, 1]))
mat = np.dot(src, np.linalg.inv(dst))[:2, :]
# Co-ordinates into output image
x, y = grid[membership == triangle_id].T
# Co-ordinates into source image
a, b = np.dot(mat, np.vstack((x, y, np.ones(len(x)))))
# Interpolate from source image to fill in the output image values
output[y, x, 0] = np.clip(image['interp_red'](b, a, grid=False), 0, 255)
output[y, x, 1] = np.clip(image['interp_green'](b, a, grid=False), 0, 255)
output[y, x, 2] = np.clip(image['interp_blue'](b, a, grid=False), 0, 255)
delaunay.close()
return output