5

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?

Community
  • 1
  • 1
Carl Witthoft
  • 19,580
  • 8
  • 40
  • 67
  • See also http://stackoverflow.com/questions/18769146/interpolating-an-irregular-grid – Andrie Sep 30 '13 at 13:03
  • possible duplicate of [Plotting interpolated data on map](http://stackoverflow.com/questions/10047870/plotting-interpolated-data-on-map) – Spacedman Sep 30 '13 at 13:17
  • @Andrie thanks-- I am looking at the `akima::interp` function and will report back. – Carl Witthoft Sep 30 '13 at 13:27
  • I'm not sure the `autoKrige` answers at the linked questions will do what I want, as the Krige functions appear to require a linear dependence on the input coordinates, whereas here I have a completely random set of ordered pairs. I may simply be undereducated as to the use of `autoKrige` . – Carl Witthoft Sep 30 '13 at 15:17

1 Answers1

1

The linked pages provide pointers to a gazillion R packages which do Kriging or other interpolation functions.

I'm posting my personal choice as an answer just to close out this question.

I found akima::interp to be a straightforward function to do 2D interpolation on arbitrary collections of sample locations.
That doesn't mean it's going to be best for everyone, and my guess is those working with geodata may prefer packages designed to muck with specific geo-survey-related file types and lat/long coordinate systems.

Carl Witthoft
  • 19,580
  • 8
  • 40
  • 67