它仍然不是最优的,因为它没有利用已知的源数据沿网格分布的事实,但是我目前发现的最好的方法是使用SciPy的最接近ndinterpolator,它基于KDTree:import scipy.interpolate
def fast_interp_irregular_grid_to_regular(
x_dst, # type: ndarray(dst_size_x) # x-values of columns in the destination image.
y_dst, # type: ndarray(dst_size_y) # y-values of rows in the destination image
x_src, # type: ndarray(src_size_y, src_sixe_x) # x-values of data points
y_src, # type: ndarray(src_size_y, src_size_x) # y-values of data points
f_src, # type: ndarray(src_size_y, src_size_x, n_dim) # values of data points.
fill_value = 0, # Value to fill in regions outside pixel hull
zero_edges = True, # Zero the edges (ensures that regions outside source grid are zero)
): # type: (...) -> array(dst_size_y, dst_size_x, n_dim) # Interpolated image
"""
Do a fast interpolation from an irregular grid