Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

interp.im

Interpolate a Pixel Image


Description

Interpolates the values of a pixel image at any desired location in the frame.

Usage

interp.im(Z, x, y=NULL, bilinear=FALSE)

Arguments

Z

Pixel image (object of class "im") with numeric or integer values.

x,y

Vectors of Cartesian coordinates. Alternatively x can be a point pattern and y can be missing.

bilinear

Logical value specifying the choice of interpolation rule. If bilinear=TRUE then a bilinear interpolation rule is used. If bilinear=FALSE (the default) then a slightly biased rule is used; this rule is consistent with earlier versions of spatstat.

Details

A value at each location (x[i],y[i]) will be interpolated using the pixel values of Z at the four surrounding pixel centres, by simple bilinear interpolation.

At the boundary (where (x[i],y[i]) is not surrounded by four pixel centres) the value at the nearest pixel is taken.

The arguments x,y can be anything acceptable to xy.coords.

Value

Vector of interpolated values, with NA for points that lie outside the domain of the image.

Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au and Rolf Turner r.turner@auckland.ac.nz, with a contribution from an anonymous user.

Examples

opa <- par(mfrow=c(1,2))
   # coarse image
   V <- as.im(function(x,y) { x^2 + y }, owin(), dimyx=10)
   plot(V, main="coarse image", col=terrain.colors(256))

   # lookup value at location (0.5,0.5)
   V[list(x=0.5,y=0.5)]
   # interpolated value at location (0.5,0.5)
   interp.im(V, 0.5, 0.5)
   interp.im(V, 0.5, 0.5, bilinear=TRUE)
   # true value is 0.75

   # how to obtain an interpolated image at a desired resolution
   U <- as.im(interp.im, W=owin(), Z=V, dimyx=256)
   plot(U, main="interpolated image", col=terrain.colors(256))
   par(opa)

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.