Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
优化插值Python_Python_Scipy_Interpolation - Fatal编程技术网

优化插值Python

优化插值Python,python,scipy,interpolation,Python,Scipy,Interpolation,我试图设计一个函数,将图像从笛卡尔坐标系转换为极坐标系。为此,我需要使用插值,但我的代码运行速度非常慢,瓶颈是以下函数: def img2polar(img, center, final_radius, angle_resolution, Xcart, Ycart): points = list(itertools.product(np.arange(0.5, img.shape[0]+0.5, 1.), np.arange(0.5, img.shape[1]+0.5, 1.)))

我试图设计一个函数,将图像从笛卡尔坐标系转换为极坐标系。为此,我需要使用插值,但我的代码运行速度非常慢,瓶颈是以下函数:

def img2polar(img, center, final_radius, angle_resolution, Xcart, Ycart):

    points = list(itertools.product(np.arange(0.5, img.shape[0]+0.5, 1.), np.arange(0.5, img.shape[1]+0.5, 1.)))

    values = np.reshape(img, img.shape[0]*img.shape[1], 'C')

    f = interpolate.griddata(points, values, (Xcart, Ycart), method='linear')

    return f
有什么办法可以加速吗


非常感谢

method=nearest
应该会更快,但问题是,如果
插值,griddata
是正确的工具吗?它似乎非常普遍,应该受到这种普遍性的影响。最靠近内极器的
interp2d
interpn
如何?通常,
点中有多少点?另外,
Xcart
Ycart
中的值是否经常变化,或者它们在不同的图像中是否相同?共有1755*525个点。值
Xcart
Ycart
在不同的图像中是相同的,但它们不在一个规则的网格中。我使用interp2d重写了它(这种方式需要使用cython编写的循环)。它稍微提高了性能,但仍然非常缓慢