Lecture 2
Lecture 2
4 Interpolation
Discrete data such as digital images and related shiftmaps are by definition
known at discrete locations on a regular grid; they are functions of two variables, x and
y directions in this case and can be also referred as a surface since the value of the
function can be viewed as the z coordinate of a 3D point (x,y,z). Such functions can be
evaluated in between the discrete points using interpolation. A priori knowledge of the
behaviour of the actual data is beneficial in the choice of interpolation function, but
most can be interpolated using bilinear or better, bicubic interpolation. In image
processing, bicubic interpolation is preferred over bilinear as the former is better at
preserving fine details in scaling applications, while bilinear is far simpler to
implement. Bicubic interpolation is frequently used in the warping, scaling and
registration algorithms referred in this thesis.
O12 Q2 O22
Y2
y P
O11 Q1 O21
Y1
X1 x X2
Figure 2-4 Interpolation in a regular lattice.
Regardless of the order of the interpolation, the concept is to evaluate the value
of a point P which falls in between known values on a regular lattice as shown in Figure
2-4.
In bilinear interpolation, it is assumed that values vary linearly along the grid
lines; however this is not true in any other direction, it takes a quadratic form as the
interpolation is performed in each direction in turn. The first step is to locate the four
34
closest points (O11, O12, O21, O22,) that surround P(x,y). The second step is to
interpolate along the x direction and evaluate the function at points Q1(x,Y1) and
Q2(x,Y2):
f(O 21 ) − f(O11 )
f(Q1 ) ≈ f(O11 ) + (x − X 1 )
X 2 − X1
2.3
f(O 22 ) − f(O12 )
f(Q 2 ) ≈ f(O12 ) + (x − X 1 )
X 2 − X1
20 0 20
10 15 5
5 20 20
(a) (b)
Figure 2-5 Bilinear interpolation. (a) greyscale (b) mesh plot.
35
2.1.4.2 Bicubic Interpolation
where the 16 coefficients aij are determined by imposing the continuity and first
derivative continuity constraints. Figure 2-6 shows the greyscale and mesh plot of the
same data points as for bilinear interpolation. The continuity of the first derivatives is
evident from the smoothness of the greyscale transition and from the surface curvature
of the mesh plot.
20 0 20
10 15 5
5 20 20
(a) (b)
Figure 2-6 Bicubic interpolation. (a) greyscale (b) mesh plot.
36
x' = a11 x + a21 y + a31
2.6
y ' = a12 x + a22 y + a32
where the aij determine the mapping function of point (x,y) as mapped into point (x’,y’).
These coefficients can be collected and the two equations written in matrix form:
⎡ a11 a12 0⎤
[ x' y ' 1] = [ x y 1]⎢⎢a 21 a 22 0⎥⎥ = [ x y 1][T] 2.7
⎢⎣ a31 a32 1⎥⎦
The seemingly useless third column of the transformation matrix [T] is retained to allow
concatenation of multiple transformations by matrix multiplication.
2.1.5.1 Translation
2.1.5.2 Rotation
Rotation is carried out about the origin of the image. All points in the xy-plane
are rotated counter clockwise by an angle θ :
⎡ cos θ sin θ 0⎤
R = ⎢⎢− sin θ cos θ 0⎥⎥ 2.9
⎢⎣ 0 0 1⎥⎦
37
2.1.5.3 Scale
Similarly to rotation, scaling works about the origin of the image, i.e., all the
distances are scaled with respect to the origin. The scale factors Sx and Sy in the x and y
directions can be different, therefore resulting in a differentially scaled image. Positive
scale factors less than unity have the effect of reducing whilst scale factors greater than
unity enlarge the image. Mirroring can be achieved by negative scale factors:
⎡S x 0 0⎤
S = ⎢⎢ 0 Sy 0⎥⎥ 2.10
⎢⎣ 0 0 1⎥⎦
2.1.5.4 Shear
Similarly, the shear transform along the y-axis keeps the x coordinates constant
whilst linearly translating the y coordinates with respect to x:
⎡1 H y 0⎤
Hy = ⎢⎢0 1 0⎥⎥ 2.12
⎢⎣0 0 1⎥⎦
38
Affine Transformation Examples
The one-dimensional function shown in Fig. 1(b) is a plot of amplitude (gray level) values of
the continuous image along the line segment AB in Fig. 1(a). The random variations are due
to image noise. To sample this function, we take equally spaced samples along line AB, as
shown in Fig. 1(c). The location of each sample is given by a vertical tick mark in the bottom
part of the figure. The samples are shown as small white squares superimposed on the
function. The set of these discrete locations gives the sampled function. However, the values
of the samples still span (vertically) a continuous range of gray-level values. In order to form
a digital function, the gray-level values also must be converted (quantized) into discrete
quantities. The right side of Fig. 1(c) shows the gray-level scale divided into eight discrete
levels, ranging from black to white. The vertical tick marks indicate the specific value
assigned to each of the eight gray levels. The continuous gray levels are quantized simply by
assigning one of the eight discrete gray levels to each sample. The assignment is made
depending on the vertical proximity of a sample to a vertical tick mark. The digital samples
resulting from both sampling and quantization are shown in Fig. 1(d). Starting at the top of
the image and carrying out this procedure line by line produces a two-dimensional digital
image.
Fig. 2(a) shows a continuous image projected onto the plane of an array sensor. Fig. 2(b)
shows the image after sampling and quantization. Clearly, the quality of a digital image is
determined to a large degree by the number of samples and discrete gray levels used in
sampling and quantization.
Fig. 1: Generating a digital image (a) Continuous image (b) A scan line from A to B in the
continuous image, used to illustrate the concepts of sampling and quantization (c) Sampling
and quantization. (d) Digital scan line.
Fig. 2: (a) Continuous image projected onto a sensor array (b) Result of image sampling and
quantization.