Bilinear interpolation

Short description: Method of interpolating functions on a 2D grid

Example of bilinear interpolation on the unit square with the z values 0, 1, 1 and 0.5 as indicated. Interpolated values in between represented by color.

In mathematics, bilinear interpolation is a method for interpolating functions of two variables (e.g., x and y) using repeated linear interpolation. It is usually applied to functions sampled on a 2D rectilinear grid, though it can be generalized to functions defined on the vertices of (a mesh of) arbitrary convex quadrilaterals.

Bilinear interpolation is performed using linear interpolation first in one direction, and then again in another direction. Although each step is linear in the sampled values and in the position, the interpolation as a whole is not linear but rather quadratic in the sample location.

Bilinear interpolation is one of the basic resampling techniques in computer vision and image processing, where it is also called bilinear filtering or bilinear texture mapping.

## Contents

* 1 Computation
* 1.1 Repeated linear interpolation
* 1.2 Polynomial fit
* 1.3 Weighted mean
* 1.4 Alternative matrix form
* 1.5 On the unit square
* 2 Properties
* 3 Inverse and generalization
* 4 Application in image processing
* 4.1 Example
* 5 A simplification of terms
* 6 See also
* 7 References

## Computation

The four red dots show the data points and the green dot is the point at which we want to interpolate.

Suppose that we want to find the value of the unknown function f at the point (x, y). It is assumed that we know the value of f at the four points Q11 = (x1, y1), Q12 = (x1, y2), Q21 = (x2, y1), and Q22 = (x2, y2).

### Repeated linear interpolation

We first do linear interpolation in the x-direction. This yields

f(x,y1)=x2−xx2−x1f(Q11)+x−x1x2−x1f(Q21),f(x,y2)=x2−xx2−x1f(Q12)+x−x1x2−x1f(Q22).

We proceed by interpolating in the y-direction to obtain the desired estimate:

f(x,y)=y2−yy2−y1f(x,y1)+y−y1y2−y1f(x,y2)=y2−yy2−y1(x2−xx2−x1f(Q11)+x−x1x2−x1f(Q21))+y−y1y2−y1(x2−xx2−x1f(Q12)+x−x1x2−x1f(Q22))=1(x2−x1)(y2−y1)(f(Q11)(x2−x)(y2−y)+f(Q12)(x2−x)(y−y1)+f(Q21)(x−x1)(y2−y)+f(Q22)(x−x1)(y−y1))=1(x2−x1)(y2−y1)[x2−xx−x1][f(Q11)f(Q12)f(Q21)f(Q22)][y2−yy−y1].

Note that we will arrive at the same result if the interpolation is done first along the y direction and then along the x direction.[1]

### Polynomial fit

An alternative way is to write the solution to the interpolation problem as a multilinear polynomial

f(x,y)≈a00+a10x+a01y+a11xy,

where the coefficients are found by solving the linear system

[1x1y1x1y11x1y2x1y21x2y1x2y11x2y2x2y2][a00a10a01a11]=[f(Q11)f(Q12)f(Q21)f(Q22)],

yielding the result

[a00a10a01a11]=1(x2−x1)(y2−y1)[x2y2−x2y1−x1y2x1y1−y2y1y2−y1−x2x2x1−x11−1−11][f(Q11)f(Q12)f(Q21)f(Q22)].

### Weighted mean

A geometric visualisation of bilinear interpolation. The product of the value at the desired point (black) and the entire area is equal to the sum of the products of the value at each corner and the partial area diagonally opposite the corner (corresponding colours).

The solution can also be written as a weighted mean of the f(Q):

f(x,y)≈w11f(Q11)+w12f(Q12)+w21f(Q21)+w22f(Q22),

where the weights sum to 1 and satisfy the transposed linear system

[1111x1x1x2x2y1y2y1y2x1y1x1y2x2y1x2y2][w11w12w21w22]=[1xyxy],

yielding the result

[w11w21w12w22]=1(x2−x1)(y2−y1)[x2y2−y2−x21−x2y1y1x2−1−x1y2y2x1−1x1y1−y1−x11][1xyxy],

which simplifies to

w11=(x2−x)(y2−y)(x2−x1)(y2−y1),w12=(x2−x)(y−y1)(x2−x1)(y2−y1),w21=(x−x1)(y2−y)(x2−x1)(y2−y1),w22=(x−x1)(y−y1)(x2−x1)(y2−y1),

in agreement with the result obtained by repeated linear interpolation. The set of weights can also be interpreted as a set of generalized barycentric coordinates for a rectangle.

### Alternative matrix form

Combining the above, we have

f(x,y)≈1(x2−x1)(y2−y1)[f(Q11)f(Q12)f(Q21)f(Q22)][x2y2−y2−x21−x2y1y1x2−1−x1y2y2x1−1x1y1−y1−x11][1xyxy].

### On the unit square

If we choose a coordinate system in which the four points where f is known are (0, 0), (0, 1), (1, 0), and (1, 1), then the interpolation formula simplifies to

f(x,y)≈f(0,0)(1−x)(1−y)+f(0,1)(1−x)y+f(1,0)x(1−y)+f(1,1)xy,

or equivalently, in matrix operations:

f(x,y)≈[1−xx][f(0,0)f(0,1)f(1,0)f(1,1)][1−yy].

Here we also recognize the weights:

w11=(1−x)(1−y),w12=(1−x)y,w21=x(1−y),w22=xy.

Alternatively, the interpolant on the unit square can be written as

f(x,y)=a00+a10x+a01y+a11xy,

where

a00=f(0,0),a10=f(1,0)−f(0,0),a01=f(0,1)−f(0,0),a11=f(1,1)−f(1,0)−f(0,1)+f(0,0).

In both cases, the number of constants (four) correspond to the number of data points where f is given.

## Properties

Comparison of Bilinear interpolation  with some 1- and 2-dimensional interpolations. Black and red/yellow/green/blue dots correspond to the interpolated point and neighbouring samples, respectively. Their heights above the ground correspond to their values.

As the name suggests, the bilinear interpolant is not linear; but it is linear (i.e. affine) along lines parallel to either the x or the y direction, equivalently if x or y is held constant. Along any other straight line, the interpolant is quadratic. Even though the interpolation is not linear in the position (x and y), at a fixed point it is linear in the interpolation values, as can be seen in the (matrix) equations above.

The result of bilinear interpolation is independent of which axis is interpolated first and which second. If we had first performed the linear interpolation in the y direction and then in the x direction, the resulting approximation would be the same.

The interpolant is a bilinear polynomial, which is also a harmonic function satisfying Laplace's equation. Its graph is a bilinear Bézier surface patch.

## Inverse and generalization

In general, the interpolant will assume any value (in the convex hull of the vertex values) at an infinite number of points (forming branches of hyperbolas[2]), so the interpolation is not invertible.

However, when bilinear interpolation is applied to two functions simultaneously, such as when interpolating a vector field, then the interpolation is invertible (under certain conditions). In particular, this inverse can be used to find the "unit square coordinates" of a point inside any convex quadrilateral (by considering the coordinates of the quadrilateral as a vector field which is bilinearly interpolated on the unit square). Using this procedure bilinear interpolation can be extended to any convex quadrilateral, though the computation is significantly more complicated if it is not a parallelogram.[3] The resulting map between quadrilaterals is known as a bilinear transformation, bilinear warp or bilinear distortion.

Alternatively, a projective mapping between a quadrilateral and the unit square may be used, but the resulting interpolant will not be bilinear.

In the special case when the quadrilateral is a parallelogram, a linear mapping to the unit square exists and the generalization follows easily.

The obvious extension of bilinear interpolation to three dimensions is called trilinear interpolation.

Inverse computation

Let F be a vector field that is bilinearly interpolated on the unit square parameterized by μ,λ∈[0,1]. Inverting the interpolation requires solving a system of two bilinear polynomial equations:A+Bλ+Cμ+Dλμ=0where A=F00−FB=F10−F00C=F01−F00D=F11−F01−F10+F00Taking a 2-d cross product (see Grassman product) of the system with a carefully chosen vectors allows us to eliminate terms:(A+Bλ+Cμ)×D=0(A+Bλ)×(C+Dλ)=0(A+Cμ)×(B+Dμ)=0which expands toc+eλ+fμ=0b+(c+d)λ+eλ2=0a+(c−d)μ+fμ2=0wherea=A×Bb=A×Cd=B×Cc=A×De=B×Df=C×DThe quadratic equations can be solved using the quadratic formula. We have the equivalent determinants 𝔻=(c+d)2−4eb=(c−d)2−4faand the solutionsλ=−c−d±𝔻2eμ=−c+d∓𝔻2f(opposite signs are enforced by the linear relation). The cases when e=0 or f=0 must be handled separately. Given the right conditions, one of the two solutions should be in the unit square.

## Application in image processing

In computer vision and image processing, bilinear interpolation is used to resample images and textures. An algorithm is used to map a screen pixel location to a corresponding point on the texture map. A weighted average of the attributes (color, transparency, etc.) of the four surrounding texels is computed and applied to the screen pixel. This process is repeated for each pixel forming the object being textured.[4]

When an image needs to be scaled up, each pixel of the original image needs to be moved in a certain direction based on the scale constant. However, when scaling up an image by a non-integral scale factor, there are pixels (i.e., holes) that are not assigned appropriate pixel values. In this case, those holes should be assigned appropriate RGB or grayscale values so that the output image does not have non-valued pixels.

Bilinear interpolation can be used where perfect image transformation with pixel matching is impossible, so that one can calculate and assign appropriate intensity values to pixels. Unlike other interpolation techniques such as nearest-neighbor interpolation and bicubic interpolation, bilinear interpolation uses values of only the 4 nearest pixels, located in diagonal directions from a given pixel, in order to find the appropriate color intensity values of that pixel.

Bilinear interpolation considers the closest 2 × 2 neighborhood of known pixel values surrounding the unknown pixel's computed location. It then takes a weighted average of these 4 pixels to arrive at its final, interpolated value.[5][6]

Example of bilinear interpolation in grayscale values

### Example

As seen in the example on the right, the intensity value at the pixel computed to be at row 20.2, column 14.5 can be calculated by first linearly interpolating between the values at column 14 and 15 on each rows 20 and 21, giving

I20,14.5=15−14.515−14⋅91+14.5−1415−14⋅210=150.5,I21,14.5=15−14.515−14⋅162+14.5−1415−14⋅95=128.5,

and then interpolating linearly between these values, giving

I20.2,14.5=21−20.221−20⋅150.5+20.2−2021−20⋅128.5=146.1.

This algorithm reduces some of the visual distortion caused by resizing an image to a non-integral zoom factor, as opposed to nearest-neighbor interpolation, which will make some pixels appear larger than others in the resized image.

## A simplification of terms

This example is of tabularised pressure (columns) vs temperature (rows) data as a lookup against some variable:

TPP1PxP2T1V11V1xV12TxVxxT2V21V2xV22

The following standard calculation by parts has 27 operations:

IT1,P1−P2=P2−PxP2−P1⋅V11+Px−P1P2−P1⋅V12=V1x,IT2,P1−P2=P2−PxP2−P1⋅V21+Px−P1P2−P1⋅V22=V2x,IPx,T1−T2=T2−TxT2−T1⋅V1x+Tx−T1T2−T1⋅V2x=Vxx.

The above has several repeated operations, e.g., (P2−P1), (Px−P1), (Px−P1), (T2−T1), as well as some ratios. These repetitions can be assigned temporary variables whilst computing a single interpolation, which will reduce the number of operations to 19.

This can all be simplified from the initial 19 individual operations to 17 individual operations as such:

Vxx=[(P2−Px)⋅V11+(Px−P1)⋅V12]⋅(T2−Tx)+[(P2−Px)⋅V21+(Px−P1)⋅V22]⋅(Tx−T1)(P2−P1)⋅(T2−T1).

Simplification of terms is good practice for application of mathematical methodology to engineering applications and can reduce computational and energy requirements for a process.[citation needed]

## See also

* Bicubic interpolation
* Trilinear interpolation
* Spline interpolation
* Lanczos resampling
* Stairstep interpolation
* Barycentric coordinates - for interpolating within a triangle or tetrahedron

## References

1. ↑ Press, William H.; Teukolsky, Saul A.; Vetterling, William T.; Flannery, Brian P. (1992). Numerical recipes in C: the art of scientific computing (2nd ed.). New York, NY, USA: Cambridge University Press. pp. 123-128. ISBN 0-521-43108-5. https://archive.org/details/numericalrecipes0865unse/page/123.
2. ↑ Monasse, Pascal (2019-08-10). "Extraction of the Level Lines of a Bilinear Image" (in en). Image Processing on Line 9: 205–219. doi:10.5201/ipol.2019.269. ISSN 2105-1232. https://www.ipol.im/pub/art/2019/269/.
3. ↑ Quilez, Inigo (2010). "Inverse bilinear interpolation". https://iquilezles.org/articles/ibilinear.
4. ↑ Bilinear interpolation definition (popular article on www.pcmag.com.
5. ↑ Khosravi, M. R. (2021-03-19). "BL-ALM: A Blind Scalable Edge-Guided Reconstruction Filter for Smart Environmental Monitoring Through Green IoMT-UAV Networks" (in en). IEEE Transactions on Green Communications and Networking 5 (2): 727–736. doi:10.1109/TGCN.2021.3067555. Bibcode: 2021ITGCN...5..727K.
6. ↑ "Web tutorial: Digital Image Interpolation".

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Bilinear interpolation. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Bilinear_interpolation&oldid=3982045"