Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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 scipy和x27中的剥落;用最近邻法计算网格数据_Python_Scipy_Interpolation - Fatal编程技术网

Python scipy和x27中的剥落;用最近邻法计算网格数据

Python scipy和x27中的剥落;用最近邻法计算网格数据,python,scipy,interpolation,Python,Scipy,Interpolation,我尝试使用最近邻法对二维图像进行插值。我正在使用scipy.interpolate中的griddata函数。问题是,与线性和立方方法不同,最近的方法不支持外推填充值,我最终得到的图像不正确 我的代码相当长,但以下是我用于插值的基本行和相关行: from scipy.interpolate import griddata vals = griddata(tuple(skewed_coords), self.values.ravel(), tuple(mesh_coords), method='ne

我尝试使用最近邻法对二维图像进行插值。我正在使用
scipy.interpolate
中的
griddata
函数。问题是,与
线性
立方
方法不同,
最近的
方法不支持外推填充值,我最终得到的图像不正确

我的代码相当长,但以下是我用于插值的基本行和相关行:

from scipy.interpolate import griddata
vals = griddata(tuple(skewed_coords), self.values.ravel(), tuple(mesh_coords), method='nearest', fill_value=-1)
最近邻法的结果只是扩展了图像的边界以进行外推:

所需结果: 下面是我期望的结果,当我指定
method='linear'
时,我得到了这个结果。但是,如果可能的话,我想使用
方法class='nearest'
,因为它更快


对于
线性
,外推和插值之间的区别很重要。但是对于最近的,这不是一个有效的区别。A(40,10)仍然离图像中的一个或另一个点最近。在事实发生后使用
fill
怎么样?我明白了,谢谢你的回答。是的,这就是我现在正在做的,但我希望有一种内置的方法来做。对于
线性
,外推和插值之间的区别很重要。但是对于最近的,这不是一个有效的区别。A(40,10)仍然离图像中的一个或另一个点最近。在事实发生后使用
fill
怎么样?我明白了,谢谢你的回答。是的,这就是我现在正在做的,但我希望有一个内置的方法来做到这一点。