What Is Bilinear Interpolation?
Bilinear interpolation is a method for estimating the value of a function at an arbitrary point within a rectangular grid, given the function values at the four corners of the grid cell. It extends linear interpolation to two dimensions by performing linear interpolation first in one direction (e.g., x), then in the other direction (y).
This technique is widely used in computer graphics, image processing, geographic information systems (GIS), and numerical analysis. It produces smoother results than nearest-neighbor interpolation while being computationally simpler than bicubic or higher-order methods.
The Bilinear Interpolation Formula
Step 1: Interpolate in x
First, perform linear interpolation along the x-axis at both y1 and y2 to get intermediate values R1 and R2.
Step 2: Interpolate in y
Then interpolate between R1 and R2 in the y direction to get the final value P.
Combined Formula
The complete bilinear interpolation can also be expressed as a single weighted sum of the four corner values.
How to Perform Bilinear Interpolation
- Identify the grid cell: Find the four corner points (x1, y1), (x2, y1), (x1, y2), and (x2, y2) that surround your target point (x, y).
- Know the corner values: Q11 = f(x1, y1), Q21 = f(x2, y1), Q12 = f(x1, y2), Q22 = f(x2, y2).
- Interpolate in x at y1: R1 = [(x2 - x)/(x2 - x1)] * Q11 + [(x - x1)/(x2 - x1)] * Q21
- Interpolate in x at y2: R2 = [(x2 - x)/(x2 - x1)] * Q12 + [(x - x1)/(x2 - x1)] * Q22
- Interpolate in y: P = [(y2 - y)/(y2 - y1)] * R1 + [(y - y1)/(y2 - y1)] * R2
Example
Suppose we have a 2D grid with corners at (0, 0), (4, 0), (0, 4), (4, 4) and values Q11 = 10, Q21 = 15, Q12 = 20, Q22 = 5. To find f(2, 2):
R1 = (4-2)/(4-0)*10 + (2-0)/(4-0)*15 = 0.5*10 + 0.5*15 = 12.5
R2 = (4-2)/(4-0)*20 + (2-0)/(4-0)*5 = 0.5*20 + 0.5*5 = 12.5
P = (4-2)/(4-0)*12.5 + (2-0)/(4-0)*12.5 = 0.5*12.5 + 0.5*12.5 = 12.5
Properties of Bilinear Interpolation
- Continuity: The interpolated surface is continuous across grid cell boundaries.
- Exact at corners: The interpolation returns the exact value at any of the four corner points.
- Not truly bilinear: Despite the name, the interpolation involves a product of x and y terms, making it a hyperbolic paraboloid surface within each cell.
- Order independence: You can interpolate first in x then y, or first in y then x -- both give the same result.
- Weighted average: The result is always a weighted average of the four corner values, so it always falls within the range [min(Q), max(Q)].
Applications
- Image processing: Resizing and rotating images requires interpolating pixel values at non-integer coordinates. Bilinear interpolation is the standard method for smooth image scaling.
- Computer graphics: Texture mapping in 3D rendering uses bilinear filtering to smooth textures when viewed at oblique angles.
- Geographic Information Systems (GIS): Estimating elevation, temperature, or other spatial data between known data points on a grid.
- Meteorology: Weather models interpolate between grid points to estimate conditions at specific locations.
- Engineering: Finite element analysis and computational fluid dynamics use interpolation within mesh cells.
- Data visualization: Creating smooth heat maps and contour plots from discrete data points.
Comparison with Other Methods
Nearest Neighbor
Simply uses the value of the closest grid point. Fast but produces blocky, discontinuous results.
Bicubic Interpolation
Uses 16 surrounding points (4x4 grid) for smoother results. Higher quality but more computationally expensive.
Tips for Accurate Interpolation
- Ensure the target point (x, y) lies within the bounds defined by x1, x2, y1, y2. Extrapolation beyond the grid may give unreliable results.
- For highly nonlinear functions, consider using bicubic or spline interpolation for better accuracy.
- x1 must differ from x2, and y1 must differ from y2, to avoid division by zero.
- The accuracy of bilinear interpolation depends on the grid resolution. Finer grids generally yield better approximations.