Linear,Bilinear,Trilinear Interpolation

from wiki

线性插值____



In this geometric visualisation, the value at the green circle multiplied by the distance between the red and blue circles is equal to the sum of the value at the red circle multiplied by the distance between the green and blue circles, and the value at the blue circle multiplied by the distance between the green and red circles.

If the two known points are given by the coordinates {\displaystyle (x_{0},y_{0})}(x_{0},y_{0}) and {\displaystyle (x_{1},y_{1})}(x_{1},y_{1}), the linear interpolant is the straight line between these points. For a value x in the interval {\displaystyle (x_{0},x_{1})}(x_{0},x_{1}), the value y along the straight line is given from the equation

{\displaystyle {\frac {y-y_{0}}{x-x_{0}}}={\frac {y_{1}-y_{0}}{x_{1}-x_{0}}},} {\displaystyle {\frac {y-y_{0}}{x-x_{0}}}={\frac {y_{1}-y_{0}}{x_{1}-x_{0}}},}

which can be derived geometrically from the figure on the right. It is a special case of polynomial interpolation with n = 1.

Solving this equation for y, which is the unknown value at x, gives

{\displaystyle y=y_{0}+(x-x_{0}){\frac {y_{1}-y_{0}}{x_{1}-x_{0}}},} {\displaystyle y=y_{0}+(x-x_{0}){\frac {y_{1}-y_{0}}{x_{1}-x_{0}}},}

which is the formula for linear interpolation in the interval {\displaystyle (x_{0},x_{1})}(x_{0},x_{1}). Outside this interval, the formula is identical to linear extrapolation.

This formula can also be understood as a weighted average. The weights are inversely related to the distance from the end points to the unknown point; the closer point has more influence than the farther point. Thus, the weights are {\textstyle {\frac {x-x_{0}}{x_{1}-x_{0}}}}{\textstyle {\frac  {x-x_{0}}{x_{1}-x_{0}}}} and {\textstyle {\frac {x_{1}-x}{x_{1}-x_{0}}}}{\textstyle {\frac  {x_{1}-x}{x_{1}-x_{0}}}}, which are normalized distances between the unknown point and each of the end points. Because these sum to 1,

{\displaystyle y=y_{0}\left(1-{\frac {x-x_{0}}{x_{1}-x_{0}}}\right)+y_{1}\left(1-{\frac {x_{1}-x}{x_{1}-x_{0}}}\right)=y_{0}\left(1-{\frac {x-x_{0}}{x_{1}-x_{0}}}\right)+y_{1}\left({\frac {x-x_{0}}{x_{1}-x_{0}}}\right),} {\displaystyle y=y_{0}\left(1-{\frac {x-x_{0}}{x_{1}-x_{0}}}\right)+y_{1}\left(1-{\frac {x_{1}-x}{x_{1}-x_{0}}}\right)=y_{0}\left(1-{\frac {x-x_{0}}{x_{1}-x_{0}}}\right)+y_{1}\left({\frac {x-x_{0}}{x_{1}-x_{0}}}\right),}

which yields the formula for linear interpolation given above.



双线性插值______

Algorithm[edit]

Suppose that we want to find the value of the unknown function f at the point (xy). It is assumed that we know the value of f at the four points Q11 = (x1y1), Q12 = (x1y2), Q21 = (x2y1), and Q22 = (x2y2).

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

{\displaystyle {\begin{aligned}f(x,y_{1})&\approx {\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{11})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{21})\\f(x,y_{2})&\approx {\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{12})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{22})\end{aligned}}}{\begin{aligned}f(x,y_{1})&\approx {\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{11})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{21})\\f(x,y_{2})&\approx {\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{12})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{22})\end{aligned}}

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

{\displaystyle {\begin{aligned}f(x,y)&\approx {\frac {y_{2}-y}{y_{2}-y_{1}}}f(x,y_{1})+{\frac {y-y_{1}}{y_{2}-y_{1}}}f(x,y_{2})\\&={\frac {y_{2}-y}{y_{2}-y_{1}}}\left({\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{11})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{21})\right)+{\frac {y-y_{1}}{y_{2}-y_{1}}}\left({\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{12})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{22})\right)\\&={\frac {1}{(x_{2}-x_{1})(y_{2}-y_{1})}}\left(f(Q_{11})(x_{2}-x)(y_{2}-y)+f(Q_{21})(x-x_{1})(y_{2}-y)+f(Q_{12})(x_{2}-x)(y-y_{1})+f(Q_{22})(x-x_{1})(y-y_{1})\right)\\&={\frac {1}{(x_{2}-x_{1})(y_{2}-y_{1})}}{\begin{bmatrix}x_{2}-x&x-x_{1}\end{bmatrix}}{\begin{bmatrix}f(Q_{11})&f(Q_{12})\\f(Q_{21})&f(Q_{22})\end{bmatrix}}{\begin{bmatrix}y_{2}-y\\y-y_{1}\end{bmatrix}}\end{aligned}}}{\displaystyle {\begin{aligned}f(x,y)&\approx {\frac {y_{2}-y}{y_{2}-y_{1}}}f(x,y_{1})+{\frac {y-y_{1}}{y_{2}-y_{1}}}f(x,y_{2})\\&={\frac {y_{2}-y}{y_{2}-y_{1}}}\left({\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{11})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{21})\right)+{\frac {y-y_{1}}{y_{2}-y_{1}}}\left({\frac {x_{2}-x}{x_{2}-x_{1}}}f(Q_{12})+{\frac {x-x_{1}}{x_{2}-x_{1}}}f(Q_{22})\right)\\&={\frac {1}{(x_{2}-x_{1})(y_{2}-y_{1})}}\left(f(Q_{11})(x_{2}-x)(y_{2}-y)+f(Q_{21})(x-x_{1})(y_{2}-y)+f(Q_{12})(x_{2}-x)(y-y_{1})+f(Q_{22})(x-x_{1})(y-y_{1})\right)\\&={\frac {1}{(x_{2}-x_{1})(y_{2}-y_{1})}}{\begin{bmatrix}x_{2}-x&x-x_{1}\end{bmatrix}}{\begin{bmatrix}f(Q_{11})&f(Q_{12})\\f(Q_{21})&f(Q_{22})\end{bmatrix}}{\begin{bmatrix}y_{2}-y\\y-y_{1}\end{bmatrix}}\end{aligned}}}

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.

Alternative algorithm[edit]

An alternative way to write the solution to the interpolation problem is

{\displaystyle f(x,y)\approx a_{0}+a_{1}x+a_{2}y+a_{3}xy}f(x,y)\approx a_{0}+a_{1}x+a_{2}y+a_{3}xy

Where the coefficients are found by solving the linear system

{\displaystyle {\begin{aligned}{\begin{bmatrix}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{bmatrix}}{\begin{bmatrix}a_{0}\\a_{1}\\a_{2}\\a_{3}\end{bmatrix}}={\begin{bmatrix}f(Q_{11})\\f(Q_{12})\\f(Q_{21})\\f(Q_{22})\end{bmatrix}}\end{aligned}}}{\begin{aligned}{\begin{bmatrix}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{bmatrix}}{\begin{bmatrix}a_{0}\\a_{1}\\a_{2}\\a_{3}\end{bmatrix}}={\begin{bmatrix}f(Q_{11})\\f(Q_{12})\\f(Q_{21})\\f(Q_{22})\end{bmatrix}}\end{aligned}}

If a solution is preferred in terms of f(Q) then we can write

{\displaystyle f(x,y)\approx b_{11}f(Q_{11})+b_{12}f(Q_{12})+b_{21}f(Q_{21})+b_{22}f(Q_{22})}f(x,y)\approx b_{11}f(Q_{11})+b_{12}f(Q_{12})+b_{21}f(Q_{21})+b_{22}f(Q_{22})

Where the coefficients are found by solving

{\displaystyle {\begin{bmatrix}b_{11}\\b_{12}\\b_{21}\\b_{22}\end{bmatrix}}=\left({\begin{bmatrix}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{bmatrix}}^{-1}\right)^{T}{\begin{bmatrix}1\\x\\y\\xy\end{bmatrix}}}{\begin{bmatrix}b_{11}\\b_{12}\\b_{21}\\b_{22}\end{bmatrix}}=\left({\begin{bmatrix}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{bmatrix}}^{-1}\right)^{T}{\begin{bmatrix}1\\x\\y\\xy\end{bmatrix}}

Unit Square[edit]

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

{\displaystyle 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.}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:

{\displaystyle f(x,y)\approx {\begin{bmatrix}1-x&x\end{bmatrix}}{\begin{bmatrix}f(0,0)&f(0,1)\\f(1,0)&f(1,1)\end{bmatrix}}{\begin{bmatrix}1-y\\y\end{bmatrix}}.}f(x,y)\approx {\begin{bmatrix}1-x&x\end{bmatrix}}{\begin{bmatrix}f(0,0)&f(0,1)\\f(1,0)&f(1,1)\end{bmatrix}}{\begin{bmatrix}1-y\\y\end{bmatrix}}.
In this geometric visualisation, the value at the black spot is the sum of the value at each coloured spot multiplied by the area of the rectangle of the same colour, divided by the total area of all four rectangles.

Nonlinear[edit]

Contrary to what the name suggests, the bilinear interpolant is not linear; but it is the product of two linear functions.

Alternatively, the interpolant can be written as

{\displaystyle f(x,y)=\sum _{i=0}^{1}\sum _{j=0}^{1}a_{ij}x^{i}y^{j}=a_{00}+a_{10}x+a_{01}y+a_{11}xy}f(x,y)=\sum _{i=0}^{1}\sum _{j=0}^{1}a_{ij}x^{i}y^{j}=a_{00}+a_{10}x+a_{01}y+a_{11}xy

where

{\displaystyle a_{00}=f(0,0)}a_{00}=f(0,0)
{\displaystyle a_{10}=f(1,0)-f(0,0)}a_{10}=f(1,0)-f(0,0)
{\displaystyle a_{01}=f(0,1)-f(0,0)}a_{01}=f(0,1)-f(0,0)
{\displaystyle a_{11}=f(1,1)+f(0,0)-(f(1,0)+f(0,1))}a_{11}=f(1,1)+f(0,0)-(f(1,0)+f(0,1))

In both cases, the number of constants (four) correspond to the number of data points where f is given. The interpolant is linear along lines parallel to either the x or the y direction, equivalently if x or y is set constant. Along any other straight line, the interpolant is quadratic. However, even if the interpolation isnot linear in the position (x and y), it is linear in the amplitude, as it is apparent from the equations above: all the coefficient bj, j=1..4, are proportional to the value of the function f(,).

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 obvious extension of bilinear interpolation to three dimensions is called trilinear interpolation.



三线性插值


Method[edit]

Eight corner points on a cube surrounding the interpolation point C
Depiction of 3D interpolation
A geometric visualisation of trilinear interpolation. The product of the value at the desired point and the entire volume is equal to the sum of the products of the value at each corner and the partial volume diagonally opposite the corner.

On a periodic and cubic lattice, let {\displaystyle x_{d}}x_{d}{\displaystyle y_{d}}y_{d}, and {\displaystyle z_{d}}z_{d} be the differences between each of {\displaystyle x}x{\displaystyle y}y{\displaystyle z}z and the smaller coordinate related, that is:

{\displaystyle \ x_{d}=(x-x_{0})/(x_{1}-x_{0})} \ x_{d}=(x-x_{0})/(x_{1}-x_{0})
{\displaystyle \ y_{d}=(y-y_{0})/(y_{1}-y_{0})} \ y_{d}=(y-y_{0})/(y_{1}-y_{0})
{\displaystyle \ z_{d}=(z-z_{0})/(z_{1}-z_{0})} \ z_{d}=(z-z_{0})/(z_{1}-z_{0})

where {\displaystyle x_{0}}x_{0} indicates the lattice point below {\displaystyle x}x, and {\displaystyle x_{1}}x_{1} indicates the lattice point above {\displaystyle x}x and similarly for {\displaystyle y_{0},y_{1},z_{0}}y_{0},y_{1},z_{0} and {\displaystyle z_{1}}z_{1}.

First we interpolate along {\displaystyle x}x (imagine we are pushing the front face of the cube to the back), giving:

{\displaystyle \ c_{00}=V[x_{0},y_{0},z_{0}](1-x_{d})+V[x_{1},y_{0},z_{0}]x_{d}} \ c_{​{00}}=V[x_{0},y_{0},z_{0}](1-x_{d})+V[x_{1},y_{0},z_{0}]x_{d}
{\displaystyle \ c_{01}=V[x_{0},y_{0},z_{1}](1-x_{d})+V[x_{1},y_{0},z_{1}]x_{d}} \ c_{​{01}}=V[x_{0},y_{0},z_{1}](1-x_{d})+V[x_{1},y_{0},z_{1}]x_{d}
{\displaystyle \ c_{10}=V[x_{0},y_{1},z_{0}](1-x_{d})+V[x_{1},y_{1},z_{0}]x_{d}} \ c_{​{10}}=V[x_{0},y_{1},z_{0}](1-x_{d})+V[x_{1},y_{1},z_{0}]x_{d}
{\displaystyle \ c_{11}=V[x_{0},y_{1},z_{1}](1-x_{d})+V[x_{1},y_{1},z_{1}]x_{d}} \ c_{​{11}}=V[x_{0},y_{1},z_{1}](1-x_{d})+V[x_{1},y_{1},z_{1}]x_{d}

Where {\displaystyle V[x_{0},y_{0},z_{0}]}V[x_{0},y_{0},z_{0}] means the function value of {\displaystyle (x_{0},y_{0},z_{0}).}(x_{0},y_{0},z_{0}). Then we interpolate these values (along {\displaystyle y}y, as we were pushing the top edge to the bottom), giving:

{\displaystyle \ c_{0}=c_{00}(1-y_{d})+c_{10}y_{d}} \ c_{0}=c_{​{00}}(1-y_{d})+c_{​{10}}y_{d}
{\displaystyle \ c_{1}=c_{01}(1-y_{d})+c_{11}y_{d}} \ c_{1}=c_{​{01}}(1-y_{d})+c_{​{11}}y_{d}

Finally we interpolate these values along {\displaystyle z}z(walking through a line):

{\displaystyle \ c=c_{0}(1-z_{d})+c_{1}z_{d}.} \ c=c_{0}(1-z_{d})+c_{1}z_{d}.

This gives us a predicted value for the point.

The result of trilinear interpolation is independent of the order of the interpolation steps along the three axes: any other order, for instance along {\displaystyle x}x, then along {\displaystyle y}y, and finally along {\displaystyle z}z, produces the same value.

The above operations can be visualized as follows: First we find the eight corners of a cube that surround our point of interest. These corners have the values C000, C100, C010, C110, C001, C101, C011, C111.

Next, we perform linear interpolation between C000 and C100 to find C00, C001 and C101 to find C01, C011 and C111 to find C11, C010 and C110 to find C10.

Now we do interpolation between C00 and C10 to find C0, C01 and C11 to find C1. Finally, we calculate the value C via linear interpolation of C0 and C1

In practice, a trilinear interpolation is identical to two bilinear interpolation combined with a linear interpolation:

{\displaystyle C\approx \ l(b(C_{000},C_{010},C_{100},C_{110}),b(C_{001},C_{011},C_{101},C_{111}))} C\approx \ l(b(C_{​{000}},C_{​{010}},C_{​{100}},C_{​{110}}),b(C_{​{001}},C_{​{011}},C_{​{101}},C_{​{111}}))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值