HOME

TheInfoList



OR:

In mathematics, bilinear interpolation is a method for
interpolating In the mathematics, mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing (finding) new data points based on the range of a discrete set of known data points. In engineering and science, one ...
functions of two variables (e.g., ''x'' and ''y'') using repeated
linear interpolation In mathematics, linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points. Linear interpolation between two known points If the two known po ...
. 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 A mesh is a barrier made of connected strands of metal, fiber, or other flexible or ductile materials. A mesh is similar to a web or a net in that it has many attached or woven strands. Types * A plastic mesh may be extruded, oriented, e ...
of) arbitrary
convex Convex or convexity may refer to: Science and technology * Convex lens, in optics Mathematics * Convex set, containing the whole line segment that joins points ** Convex polygon, a polygon which encloses a convex set of points ** Convex polytop ...
quadrilateral In geometry a quadrilateral is a four-sided polygon, having four edges (sides) and four corners (vertices). The word is derived from the Latin words ''quadri'', a variant of four, and ''latus'', meaning "side". It is also called a tetragon, ...
s. Bilinear interpolation is performed using linear interpolation first in one direction, and then again in the other 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 mathematics, the term quadratic describes something that pertains to squares, to the operation of squaring, to terms of the second degree, or equations or formulas that involve such terms. ''Quadratus'' is Latin for ''square''. Mathematics ...
in the sample location. Bilinear interpolation is one of the basic resampling techniques in
computer vision Computer vision is an Interdisciplinarity, interdisciplinary scientific field that deals with how computers can gain high-level understanding from digital images or videos. From the perspective of engineering, it seeks to understand and automate t ...
and
image processing An image is a visual representation of something. It can be two-dimensional, three-dimensional, or somehow otherwise feed into the visual system to convey information. An image can be an artifact, such as a photograph or other two-dimension ...
, where it is also called bilinear filtering or bilinear texture mapping.


Computation

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 ''Q''11 = (''x''1, ''y''1), ''Q''12 = (''x''1, ''y''2), ''Q''21 = (''x''2, ''y''1), and ''Q''22 = (''x''2, ''y''2).


Repeated linear interpolation

We first do linear interpolation in the ''x''-direction. This yields :\begin f(x, y_1) = \frac f(Q_) + \frac f(Q_), \\ f(x, y_2) = \frac f(Q_) + \frac f(Q_). \end We proceed by interpolating in the ''y''-direction to obtain the desired estimate: :\begin f(x,y) &= \frac f(x, y_1) + \frac f(x, y_2) \\ &= \frac \left( \frac f(Q_) + \frac f(Q_) \right) + \frac \left( \frac f(Q_) + \frac f(Q_) \right) \\ &= \frac \left( f(Q_)(x_2-x)(y_2-y) + f(Q_)(x-x_1)(y_2-y)+ f(Q_)(x_2-x)(y-y_1) + f(Q_)(x-x_1)(y-y_1) \right) \\ &= \frac \begin x_2-x & x-x_1 \end \begin f(Q_) & f(Q_) \\ f(Q_) & f(Q_) \end \begin y_2-y \\ y-y_1 \end. \end 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.


Polynomial fit

An alternative way is to write the solution to the interpolation problem as a
multilinear polynomial In algebra, a multilinear polynomial is a multivariate polynomial that is linear (meaning affine) in each of its variables separately, but not necessarily simultaneously. It is a polynomial in which no variable occurs to a power of 2 or higher ...
:f(x, y) \approx a_ + a_x + a_y + a_xy, where the coefficients are found by solving the linear system :\begin \begin 1 & x_1 & y_1 & x_1 y_1 \\ 1 & x_1 & y_2 & x_1 y_2 \\ 1 & x_2 & y_1 & x_2 y_1 \\ 1 & x_2 & y_2 & x_2 y_2 \end\begin a_\\a_\\a_\\a_ \end = \begin f(Q_)\\f(Q_)\\f(Q_)\\f(Q_) \end, \end yielding the result :\begin \begin a_\\a_\\a_\\a_ \end = \frac\begin x_2y_2 & -x_2y_1 & -x_1y_2 & x_1y_1 \\ -y_2 & y_1 & y_2 & -y_1 \\ -x_2 & x_2 & x_1 & -x_1 \\ 1 & -1 & -1 & 1 \end\begin f(Q_)\\f(Q_)\\f(Q_)\\f(Q_) \end. \end


Weighted mean

The solution can also be written as a
weighted mean The weighted arithmetic mean is similar to an ordinary arithmetic mean (the most common type of average), except that instead of each of the data points contributing equally to the final average, some data points contribute more than others. The ...
of the ''f''(''Q''): :f(x, y) \approx w_ f(Q_) + w_ f(Q_) + w_ f(Q_) + w_ f(Q_), where the weights sum to 1 and satisfy the transposed linear system : \begin 1 & 1 & 1 & 1 \\ x_1 & x_1 & x_2 & x_2 \\ y_1 & y_2 & y_1 & y_2 \\ x_1y_1 & x_1y_2 & x_2y_1 & x_2y_2 \end \begin w_ \\ w_ \\ w_ \\ w_ \end = \begin 1 \\ x \\ y \\ xy \end, yielding the result :\begin \begin w_\\w_\\w_\\w_ \end = \frac\begin x_2y_2 & -y_2 & -x_2 & 1 \\ -x_2y_1 & y_1 & x_2 & -1 \\ -x_1y_2 & y_2 & x_1 & -1 \\ x_1y_1 & -y_1 & -x_1 & 1 \end\begin 1\\x\\y\\xy \end, \end which simplifies to :\begin w_ &= (x_2 - x )(y_2 - y ) / ((x_2 - x_1)(y_2 - y_1)), \\ w_ &= (x_2 - x )(y - y_1) / ((x_2 - x_1)(y_2 - y_1)), \\ w_ &= (x - x_1)(y_2 - y ) / ((x_2 - x_1)(y_2 - y_1)), \\ w_ &= (x - x_1)(y - y_1) / ((x_2 - x_1)(y_2 - y_1)), \end 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 :\begin f(x,y) \approx \frac \beginf(Q_) & f(Q_) & f(Q_) & f(Q_)\end\begin x_2y_2 & -y_2 & -x_2 & 1 \\ -x_2y_1 & y_1 & x_2 & -1 \\ -x_1y_2 & y_2 & x_1 & -1 \\ x_1y_1 & -y_1 & -x_1 & 1 \end\begin 1\\x\\y\\xy \end. \end


On the unit square

If we choose a coordinate system in which the four points where ''f'' is known are (0, 0), (1, 0), (0, 1), and (1, 1), then the interpolation formula simplifies to :f(x, y) \approx f(0, 0) (1 - x)(1 - y) + f(1, 0) x(1 - y) + f(0, 1) (1 - x)y + f(1, 1) xy, or equivalently, in matrix operations: :f(x, y) \approx \begin 1 - x & x \end \begin f(0, 0) & f(0, 1) \\ f(1, 0) & f(1, 1) \end \begin 1 - y \\ y \end. Here we also recognize the weights: :\begin w_ &= (1 - x)(1 - y), \\ w_ &= (1 - x)y, \\ w_ &= x(1 - y), \\ w_ &= xy. \end Alternatively, the interpolant on the unit square can be written as :f(x, y) = a_ + a_x + a_y + a_xy, where :\begin a_ &= f(0, 0), \\ a_ &= f(1, 0) - f(0, 0), \\ a_ &= f(0, 1) - f(0, 0), \\ a_ &= f(1, 1) - f(1, 0) - f(0, 1) + f(0, 0). \end In both cases, the number of constants (four) correspond to the number of data points where ''f'' is given.


Properties

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 In mathematics, the term quadratic describes something that pertains to squares, to the operation of squaring, to terms of the second degree, or equations or formulas that involve such terms. ''Quadratus'' is Latin for ''square''. Mathematics ...
. 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 In mathematics, mathematical physics and the theory of stochastic processes, a harmonic function is a twice continuously differentiable function f: U \to \mathbb R, where is an open subset of that satisfies Laplace's equation, that is, ...
satisfying Laplace's equation. Its
graph Graph may refer to: Mathematics *Graph (discrete mathematics), a structure made of vertices and edges **Graph theory, the study of such graphs and their properties *Graph (topology), a topological space resembling a graph in the sense of discre ...
is a bilinear
Bézier surface Bézier surfaces are a species of mathematical spline used in computer graphics, computer-aided design, and finite element modeling. As with Bézier curves, a Bézier surface is defined by a set of control points. Similar to interpolation in ...
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
hyperbola In mathematics, a hyperbola (; pl. hyperbolas or hyperbolae ; adj. hyperbolic ) is a type of smooth curve lying in a plane, defined by its geometric properties or by equations for which it is the solution set. A hyperbola has two pieces, c ...
s), 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 Convex or convexity may refer to: Science and technology * Convex lens, in optics Mathematics * Convex set, containing the whole line segment that joins points ** Convex polygon, a polygon which encloses a convex set of points ** Convex polytop ...
quadrilateral In geometry a quadrilateral is a four-sided polygon, having four edges (sides) and four corners (vertices). The word is derived from the Latin words ''quadri'', a variant of four, and ''latus'', meaning "side". It is also called a tetragon, ...
(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. The resulting map between quadrilaterals is known as a ''bilinear transformation'', ''bilinear warp'' or ''bilinear distortion''. Alternatively, a
projective map In projective geometry, a homography is an isomorphism of projective spaces, induced by an isomorphism of the vector spaces from which the projective spaces derive. It is a bijection that maps lines to lines, and thus a collineation. In general, s ...
ping 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 In Euclidean geometry, a parallelogram is a simple (non- self-intersecting) quadrilateral with two pairs of parallel sides. The opposite or facing sides of a parallelogram are of equal length and the opposite angles of a parallelogram are of eq ...
, 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. Let F be a vector field that is bilinearly interpolated on the unit square parameterized by \mu, \lambda \in ,1/math>. Inverting the interpolation requires solving a system of two bilinear polynomial equations:A + B\lambda + C\mu + D\lambda\mu = 0where \begin A &= F_ - F \\ B &= F_ - F_ \\ C &= F_ - F_ \\ D &= F_ - F_ - F_ + F_ \endTaking a 2-d cross product (see Grassman product) of the system with a carefully chosen vectors allows us to eliminate terms:\begin (A + B\lambda + C\mu) &\times D &= 0 \\ (A + B\lambda) &\times (C + D\lambda) &= 0 \\ (A + C\mu) &\times (B + D\mu) &= 0 \\ \endwhich expands to\begin c + e\lambda + f\mu &= 0 \\ b + (c + d)\lambda + e\lambda^2&= 0 \\ a + (c - d)\mu + f\mu^2&= 0 \\ \endwhere\begin a &= A \times B \\ b &= A \times C \qquad d = B \times C \\ c &= A \times D \qquad e = B \times D \qquad f = C \times D \endThe quadratic equations can be solved using the
quadratic formula In elementary algebra, the quadratic formula is a formula that provides the solution(s) to a quadratic equation. There are other ways of solving a quadratic equation instead of using the quadratic formula, such as factoring (direct factoring, g ...
. We have the equivalent determinants \mathbb = (c + d)^2 -4eb = (c - d)^2 - 4faand the solutions\lambda = \frac \qquad \mu = \frac(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 Computer vision is an Interdisciplinarity, interdisciplinary scientific field that deals with how computers can gain high-level understanding from digital images or videos. From the perspective of engineering, it seeks to understand and automate t ...
and
image processing An image is a visual representation of something. It can be two-dimensional, three-dimensional, or somehow otherwise feed into the visual system to convey information. An image can be an artifact, such as a photograph or other two-dimension ...
, 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 In Computer graphics, computer graphics, a texel, texture element, or texture pixel is the fundamental unit of a texture maps, texture map. Textures are represented by Array data structure, arrays of texels representing the texture space, just a ...
is computed and applied to the screen pixel. This process is repeated for each pixel forming the object being textured. 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 In digital photography, computer-generated imagery, and colorimetry, a grayscale image is one in which the value of each pixel is a single sample representing only an ''amount'' of light; that is, it carries only intensity information. Graysc ...
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."Web tutorial: Digital Image Interpolation"


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 :\begin I_ &= \frac \cdot 91 + \frac \cdot 210 = 150.5, \\ I_ &= \frac \cdot 162 + \frac \cdot 95 = 128.5, \end and then interpolating linearly between these values, giving :I_ = \frac \cdot 150.5 + \frac{21 - 20} \cdot 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.


See also

* Bicubic interpolation * Trilinear interpolation *
Spline interpolation In the mathematical field of numerical analysis, spline interpolation is a form of interpolation where the interpolant is a special type of piecewise polynomial called a spline. That is, instead of fitting a single, high-degree polynomial to all ...
* Lanczos resampling * Stairstep interpolation * Barycentric coordinates - for interpolating within a triangle or tetrahedron


References

Multivariate interpolation