我'm trying to interpolate a sparse matrix to fill the 0 values. I' m使用numpy griddata
函数从可用的示例here开始 . 作为参考,我开始的数据具有1通道图像的形状,看起来像这样(每4x4大约1个数据点):
应该进行插值的代码是这样的:
# a contains the data
grid_y, grid_x = np.mgrid[0:128:1, 0:384:1]
points = []
for z in zip(a.nonzero()[0],a.nonzero()[1]):
points.append(np.array(z))
values = [a[x] for x in zip(a.nonzero()[0],a.nonzero()[1])]
interp = griddata(points, values, (grid_x, grid_y), method='cubic')
但由于某种原因,这是插值的结果:
图像中的白色部分实际上是NaN . 从我对这个例子的理解来看,我真的可以做错了 . 有任何想法吗?
谢谢!
1 回答
您只是插入到x轴的范围,因为
grid_x
和grid_y
在示例的最后一行按顺序交换 . 就像这样反转