I have nonuniformly located samples of an image, and would like to interpolate to a regular grid because (among other things) most image graphics functions expect a regular grid.
I notice there are some MatLab functions (see Image interpolation from random pixels for example) which apparently will do this, but couldn't find an R-package that does.
Here's a simple example.
#make up some 2D func
y<-matrix(rep(1:10,10) -.5 + runif(100),nrow=10)
x<-matrix(rep(1:10,10) -.5 + runif(100),nrow=10)
inmat<-sin(x) + cos(y)
So the values of inmat
are on random locations. I want some sort of outmat<-interpolate(inmat,x,y,gridx,gridy)
function where inmat
, x
,and y
are either all matrices or all vectors (unwrapped matrices).
I see also that SciPy has http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html which does this. Is there such a function in an R
package or do I need to port from SciPy
or MatLab
code?