What is bilinear interpolation?

Bilinear interpolation is used to compute an output pixel value based on a weighted average of its four nearest pixels. It is mainly used when scaling up an image, rotating it, or performing 3D rendering.

Note: The "bi" prefix indicates that the interpolation is performed in two directions (horizontally and vertically).

How bilinear interpolation works

Bilinear interpolation is an extension of the linear interpolation for interpolating functions of the two variables (xx and yy) on a 2D grid. The key idea is to perform linear interpolation first in one direction, and then in the other direction.

It considers the closest 2×22 \times 2 neighborhood of known pixel values surrounding an unknown pixel. It then takes the weighted average of these 4 pixels to arrive at the final interpolated value.

Advantages of bilinear interpolation

The major advantages for using bilinear interpolation are given below.

  • Better approximation of data: For 2D datasets, linear interpolationInterpolation in one direction. can lead to estimates that are not smooth. Bilinear interpolationInterpolation in x and y direction. can provide a smoother and more accurate approximation of the data.

  • Sub-pixel accuracy in images: In digital image processing, bilinear interpolation is often used to perform tasks such as resizing, zooming, translation, and rotation. It allows us to estimate pixel values at non-integer pixel locations, providing accuracy. It is important when transforming images, as it helps maintain the images' continuity.

  • Simple and efficient: While more complex methods for interpolation, such as bicubic or spline interpolation, can offer even smoother results, bilinear interpolation strikes a good balance between simplicity, performance, and accuracy. It involves only a few mathematical operations, making it an efficient and suitable method for real-time applications.

How to calculate the interpolated value

The process of bilinear interpolation involves two steps:

  • Interpolation in the horizontal (xx) direction

  • Interpolation in the vertical (yy) direction

The complete process of finding the interpolated value is given below.

  • Assume a 2×22 \times 2 grid of points as follows.

Bilinear interpolation: 2D grid
Bilinear interpolation: 2D grid

Here,

  • Q11,Q12,Q21,Q22Q_{11}, Q_{12}, Q_{21}, Q_{22} are the values of the four points on the grid.

  • The point P(x,y)P(x, y) is an arbitrary point for which we want to find the color intensity value.

  • Horizontal interpolation

    • R1=Q11×(1x)+Q21×xR_1 = Q_{11} \times (1 - x) + Q_{21} \times x

    • R2=Q21(1x)+Q22xR_2 = Q_{21} * (1 - x) + Q_{22} * x

Note: xx is the distance of the point pp from Q11Q_{11} along the x-axis.

  • Vertical interpolation

    • P=R1×(1y)+R2×yP = R_1 \times (1 - y) + R_2 \times y

Note: yy is the fractional distance of the point pp from Q11Q_{11} along the y-axis.

Example

The intensity values of the pixels at the corners of the grid are given below.

  • Q11=10Q_{11} = 10

  • Q12=20Q_{12} = 20

  • Q21=30Q_{21} = 30

  • Q22=40Q_{22} = 40

Let's say that the point PP is 0.2 units to the right and 0.6 units up, P(0.2,0.6P(0.2, 0.6).

Horizontal interpolation

  • Interpolation on the bottom row

  • Interpolation on the top row

  • Vertical interpolation (interpolation between R1R_1 and R2R_2)

Example of bilinear interpolation
Example of bilinear interpolation

For the point P(x,y)P(x, y), the bilinear interpolated intensity value is 24. The intensity value considers the relative proximity of the point PP to each of the four grid points and their respective intensities.

Learn more


Copyright ©2024 Educative, Inc. All rights reserved