Scipy interp2d内插蒙版填充值 [英] Scipy interp2d interpolate masked fill values

查看:151
本文介绍了Scipy interp2d内插蒙版填充值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to interpolate data (120*120) in order to get output data (1200*1200).

通过这种方式,我正在使用

In this way I'm using scipy.interpolate.interp2d.

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

Below is my input data, where 255 corresponds to fill values, I mask these values before the interpolation.

我正在使用以下代码:

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)

我得到以下结果:

填充值已内插.

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

How can I interpolate my data without interpolate fill values ?

推荐答案

我找到了

I found a solution with scipy.interpolate.griddata but I'm not sure that's the best one.

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

I interpolate data with the nearest method parameter which returns the value at the data point closest to the point of interpolation.

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))

这篇关于Scipy interp2d内插蒙版填充值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆