Looking at the documentation you should note a few things:
If x and y represent a regular grid, consider using RectBivariateSpline.
x
andy
should be 1D vectors unlike in Matlab and they match with Matlab'sx
andy
and NOT withxi
andyi
. Those come later.SciPy will return a function to use to interpolate later. Matlab retuns the interpolated vector immediately.
You've used it in Matlab but implicitly assuming that
[X, Y] = meshgrid(1:size(I,1), 1:size(I,2))
gt= interp2(X, Y, I(:,:,i)',xi,yi,'cubic')';
So it's actually this X
and Y
that you need to pass to interpolation.interp2d and NOT xi
and yi
, they come later.
In SciPy you can actually skip the meshgrid
step and just use a normal range but also it outputs a function for later rather than performing the interpolation on the spot (note there might be small errors in my definitions of x
and y
, I'm not that familiar with arange
):
x = arange(1, img.shape[0]+1)
y = arange(1, img.shape[1]+1)
f = interpolation.interp2d(x, y, img.T)
and then when you want to do the interpolation:
gt = f(xi, yi)