regrid(x,xgrid,ygrid,sx,sy)
and
regrid3(x,xgrid,ygrid,sx,sy)
work as described below. The mapped
image values are interpolated from the source image x
on a double
grid. The coordinates of the points of the coarse grid, measured in the
coordinate system of x
, are given by xgrid
and
ygrid
. A fine grid of sx
by sy
points is spread
evenly over each cell of the coarse grid, and each point of the fine
grid corresponds to a single element of the mapped image. The image
value at each point of the fine grid is determined through
nearest-neighbor (regrid
) or bicubic (regrid3
)
interpolation.
For example, the x coordinates of the points on the fine grid in the
cell identified by cell indices i
and j
are given by
(xgrid(i+1,j) - xgrid(i,j))*ix/sx + (xgrid(i,j+1) -
xgrid(i,j))*iy/sy + (xgrid(i+1,j+1) + xgrid(i,j) - xgrid(i+1,j) -
xgrid(i,j + 1))*ix*iy/(sx*sy)
for integer ix
between 0 and
sx
- 1 and integer iy
between 0 and sy
- 1.
For linear transformations, such as combinations of rotations, scalings, and translations, only one grid cell (two by two coordinates) is needed.
The bicubic interpolation (for regrid3
) is based on the sequence
i = floor(x) b = x - i a = 1 - b w1 = -0.5*b*a*a w2 = 1 + b*b*(1.5*b - 2.5) w3 = 1 + a*a*(1.5*a - 2.5) w4 = -0.5*a*b*b y_interp = y(i-1)*w1 + y(i)*w2 + y(i+1)*w3 + y(i+2)*w4
which yields y_interp
at ordinate x
, interpolated from
y
. Application in two dimensions yields bicubic interpolation.
This particular form of bicubic interpolation is due to s.k. Park and
r.a. Schowengerdt (1983: Comp. Vis. & Im. Proc., Vol. 23, p. 258; with
alpha = -0.5).