Bilinear Filtering - The Formula

The Formula

In a mathematical context, bilinear interpolation is the problem of finding a function f(x,y) of the form

f(x,y) = c11xy + c10x + c01y + c00 satisfying

f(x1,y1) = z11, f(x1,y2) = z12, f(x2,y1) = z21, and f(x2,y2) = z22.

The usual, and usually computationally least expensive way to compute f is through linear interpolation used twice, for example to compute two functions f1 and f2, satisfying

f1(y1) = z11, f1(y2) = z12, f2(y1) = z21, and f2(y2) = z22,

and then to combine these functions (which are linear in y) into one function f satisfying

f(x1,y) = f1(y), and f(x2,y) = f1(y).


In computer graphics, bilinear filtering is usually performed on a texture during texture mapping, or on a bitmap during resizing. In both cases, the source data (bitmap or texture) can be seen as a two-dimensional array of values zij, or several (usually three) of these in the case of full-color data. The data points used in bilinear filtering are the 2x2 points surrounding the location for which the color is to be interpolated.

Additionally, one does not have to compute the actual coefficients of the function f; computing the value f(x,y) is sufficient.

The largest integer not larger than x shall be called, and the fractional part of x shall be {x}. Then, x = + {x}, and {x} < 1. We have x1 =, x2 = + 1, y1 =, y2 = + 1. The data points used for interpolation are taken from the texture / bitmap and assigned to z11, z12, z21, and z22.

f1(y1) = z11, f1(y2) = z12 are the two data points for f1; subtracting the former from the latter yields

f1(y2) - f1(y1) = z12 - z11.

Because f1 is linear, its derivative is constant and equal to

(z12 - z11) / (y2 - y1) = z12 - z11.

Because f1(y1) = z11,

f1(y1 + {y}) = z11 + {y}(z12 - z11),

and similarly,

f2(y1 + {y}) = z21 + {y}(z22 - z21).

Because y1 + {y} = y, we have computed the endpoints f1(y) and f2(y) needed for the second interpolation step.

The second step is to compute f(x,y), which can be accomplished by the very formula we used for computing the intermediate values:

f(x,y) = f1(y) + {x}(f2(y) - f1(y)).

In the case of scaling, y remains constant within the same line of the rescaled image, and storing the intermediate results and reusing them for calculation of the next pixel can lead to significant savings. Similar savings can be achieved with all "bi" kinds of filtering, i.e. those which can be expressed as two passes of one-dimensional filtering.

In the case of texture mapping, a constant x or y is rarely if ever encountered, and because today's (2000+) graphics hardware is highly parallelized, there would be no time savings anyway.

Another way of writing the bilinear interpolation formula is

f(x,y) = (1-{x})((1-{y})z11 + {y}z12) + {x}((1-{y})z21 + {y}z22).

Read more about this topic:  Bilinear Filtering

Famous quotes containing the word formula:

    In the most desirable conditions, the child learns to manage anxiety by being exposed to just the right amounts of it, not much more and not much less. This optimal amount of anxiety varies with the child’s age and temperament. It may also vary with cultural values.... There is no mathematical formula for calculating exact amounts of optimal anxiety. This is why child rearing is an art and not a science.
    Alicia F. Lieberman (20th century)

    Every formula which expresses a law of nature is a hymn of praise to God.
    Maria Mitchell (1818–1889)