Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/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 interp2d插值遮罩填充值_Python_Arrays_Numpy_Scipy_Interpolation - Fatal编程技术网

Python Scipy interp2d插值遮罩填充值

Python Scipy interp2d插值遮罩填充值,python,arrays,numpy,scipy,interpolation,Python,Arrays,Numpy,Scipy,Interpolation,我想插值数据(120*120)以获得输出数据(1200*1200) 我就是这样用的 下面是我的输入数据,其中255对应于填充值,我在插值之前屏蔽这些值 points = np.meshgrid(np.linspace(0, 1200, data.shape[1]), np.linspace(0, 1200, data.shape[0])) points = zip(points[0].flatten(), points[1].flatten()) xi

我想插值数据(120*120)以获得输出数据(1200*1200)

我就是这样用的

下面是我的输入数据,其中255对应于填充值,我在插值之前屏蔽这些值

points = np.meshgrid(np.linspace(0, 1200, data.shape[1]),
                     np.linspace(0, 1200, data.shape[0]))
points = zip(points[0].flatten(), points[1].flatten())
xi = np.meshgrid(np.arange(1200), np.arange(1200))
xi = zip(xi[0].flatten(), xi[1].flatten())

tck = griddata(np.array(points), data.flatten(), np.array(xi), method='nearest')
data = tck.reshape((1200, 1200))

我正在使用下面的代码:

tck = interp2d(np.linspace(0, 1200, data.shape[1]),
               np.linspace(0, 1200, data.shape[0]),
               data,
               fill_value=255)
data = tck(range(1200), range(1200))
data = np.ma.MaskedArray(data, data == 255)
我得到以下结果:

填充值已插值

如何在不插值填充值的情况下插值数据?

我找到了一个解决方案,但我不确定这是最好的

我使用
最近的
方法参数插值数据,该参数返回最接近插值点的数据点处的值

points = np.meshgrid(np.linspace(0, 1200, data.shape[1]),
                     np.linspace(0, 1200, data.shape[0]))
points = zip(points[0].flatten(), points[1].flatten())
xi = np.meshgrid(np.arange(1200), np.arange(1200))
xi = zip(xi[0].flatten(), xi[1].flatten())

tck = griddata(np.array(points), data.flatten(), np.array(xi), method='nearest')
data = tck.reshape((1200, 1200))