我用过interp2
在Matlab中,例如以下代码,这是@rayryeng的答案的一部分:Matlab 中的三维 (3D) 矩阵插值:
d = size(volume_image)
[X,Y] = meshgrid(1:1/scaleCoeff(2):d(2), 1:1/scaleCoeff(1):d(1));
for ind = z
%Interpolate each slice via interp2
M2D(:,:,ind) = interp2(volume_image(:,:,ind), X, Y);
end
尺寸示例:
The image size is 512x512 and the number of slices is 133. So:
volume_image(rows, columns, slices in 3D dimenson) : 512x512x133 in 3D dimenson
X: 288x288
Y: 288x288
scaleCoeff(2): 0.5625
scaleCoeff(1): 0.5625
z = 1 up to 133 ,hence z: 1x133
ind: 1 up to 133
M2D(:,:,ind) finally is 288x288x133 in 3D dimenson
Aslo,大小的 Matlabs 语法:(第三维中的行、列、切片)和大小的 Python 语法:(第三维中的切片、行、列)。
但是,将Matlab代码转换为Python代码后出现错误,ValueError: Invalid length for input z for non rectangular grid
:
for ind in range(0, len(z)+1):
M2D[ind, :, :] = interpolate.interp2d(X, Y, volume_image[ind, :, :]) # ValueError: Invalid length for input z for non rectangular grid
怎么了?太感谢了。