Python中3d插值函数的逐元素求值

时间:2019-05-27 13:43:35

标签: arrays function 3d interpolation evaluation

我有一个3D数据阵列,来自显微镜照片,尺寸为(16,24,20)。我想将图片插值到更细的网格,就像在Matlab中使用

Vq = interp3(X,Y,Z,V,Xq,Yq,Zq)

我尝试了以下方法:

# Get the dimensions of the picture
   x_length, y_length, z_length=np.shape(im)

# Create a mesh with the same dimensions and spacing

   MainGrid_x=np.arange(0, x_length, 1)

   MainGrid_y=np.arange(0, y_length, 1)

   MainGrid_z=np.arange(0, z_length, 1)

   X,Y,Z=np.meshgrid(MainGrid_y,MainGrid_x,MainGrid_z)

# Create a 3D interpolating function

   from scipy.interpolate import RegularGridInterpolator as rgi

   interp_fun= rgi((MainGrid_x,MainGrid_y,MainGrid_z), im)

# And define a finer grid, where I can evaluate the function

   interp_factor=2

   FineGrid_x=np.arange(0, x_length, 1/interp_factor)

   FineGrid_y=np.arange(0, y_length, 1/interp_factor)

   FineGrid_z=np.arange(0, z_length, 1/interp_factor)

   Xx,Yy,Zz=np.meshgrid(FineGrid_y, FineGrid_x, FineGrid_z)

但是,在评估方面,似乎没有简单的方法

InterpIm=interp_fun(FineGrid_y, FineGrid_x, FineGrid_z)

返回错误“ 调用()需要2到3个位置参数,但给出了4个”

InterpIm=interp_fun(Xx,Yy,Zz)

有没有简单的方法可以在精细的3D网格中评估插值函数?

0 个答案:

没有答案