記事ディレクトリ
参考文献
序文
共一次補間。共一次補間とも呼ばれます。数学的には、双一次補間は、x と y などの 2 変数関数を補間するための 2 次元長方形グリッド上の線形補間の拡張です。中心となるアイデアは、x 方向と y 方向にそれぞれ線形補間を実行することです。
線形補間については、以前の。
派生する
未知の関数ffを取得したい場合点P = ( x , y ) P=(x, y)におけるfP=( x ,y )、関数fffにおいてQ 11 = ( x 1 , y 1 ) 、 Q 12 = ( x 1 , y 2 ) 、 Q 21 = ( x 2 , y 1 ) Q_{11}=\left(x_1, y_1\right) 、 Q_ {12}=\left(x_1, y_2\right) , Q_{21}=\left(x_2, y_1\right)Q11=( ×1、y1)、Q12=( ×1、y2)、Q21=( ×2、y1),Q 22 = ( x 2 , y 2 ) Q_{22}=\left(x_2, y_2\right)Q22=( ×2、y2) 4 点の値。
![](https://img-blog.csdnimg.cn/6a64d9c3c0fb4c8eb6d1a2c2437877f3.png#pic_center?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjEwMTgzOQ==,size_16,color_FFFFFF,t_70)
最初に x 方向、次に y 方向
まずはxx時x方向の線形補間xxx变、yyy不変),
f ( x , y 1 ) ≈ x 2 − xx 2 − x 1 f ( Q 11 ) + x − x 1 x 2 − x 1 f ( Q 21 ) , f ( x , y 2 ) を得る≈ x 2 − xx 2 − x 1 f (Q 12 ) + x − x 1 x 2 − x 1 f (Q 22 ) 。\begin{aligned} & f\left(x, y_1\right) \about \frac{x_2-x}{x_2-x_1} f\left(Q_{11}\right)+\frac{x-x_1}{ x_2-x_1} f\left(Q_{21}\right), \\ & f\left(x, y_2\right) \about \frac{x_2-x}{x_2-x_1} f\left(Q_{12 }\right)+\frac{x-x_1}{x_2-x_1} f\left(Q_{22}\right) 。\end{整列}f( x ,y1)≈バツ2−バツ1バツ2−×f( Q11)+バツ2−バツ1バツ−バツ1f( Q21)、f( x ,y2)≈バツ2−バツ1バツ2−×f( Q12)+バツ2−バツ1バツ−バツ1f( Q22).
それからyyにy方向に線形補間を実行して、
f ( x , y ) ≈ y 2 − yy 2 − y 1 f ( x , y 1 ) + y − y 1 y 2 − y 1 f ( x , y 2 ) = y 2 − yy 2 − y 1 ( x 2 − xx 2 − x 1 f ( Q 11 ) + x − x 1 x 2 − x 1 f ( Q 21 ) ) + y − y 1 y 2 − y 1 ( x 2 − xx 2 − x 1 f ( Q 12 ) + x − x 1 x 2 − x 1 f ( Q 22 ) ) = 1 ( x 2 − x 1 ) ( y 2 − y 1 ) ( 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 ) ) = 1 ( x 2 − x 1 ) ( y 2 − y 1 ) [ x 2 − xx − x 1 ] [ f ( Q 11 ) f ( Q 12 ) f ( Q 21 ) f ( Q 22 ) ] [ y 2 − yy − y 1 ] 。\begin{aligned} f(x, y) & \about \frac{y_2-y}{y_2-y_1} f\left(x, y_1\right)+\frac{y-y_1}{y_2-y_1} f \left(x, y_2\right) \\ & =\frac{y_2-y}{y_2-y_1}\left(\frac{x_2-x}{x_2-x_1} f\left(Q_{11}\right)+\frac{x-x_1}{x_2- x_1} f\left(Q_{21}\right)\right)+\frac{y-y_1}{y_2-y_1}\left(\frac{x_2-x}{x_2-x_1} f\left(Q_{ 12}\right)+\frac{x-x_1}{x_2-x_1} f\left(Q_{22}\right)\right) \\ & =\frac{1}{\left(x_2-x_1\right) )\left(y_2-y_1\right)}\left(f\left(Q_{11}\right)\left(x_2-x\right)\left(y_2-y\right)+f\left(Q_{ 21}\right)\left(x-x_1\right)\left(y_2-y\right)+f\left(Q_{12}\right)\left(x_2-x\right)\left(y-y_1 \right)+f\left(Q_{22}\right)\left(x-x_1\right)\left(y-y_1\right)\right) \\ & =\frac{1}{\left(x_2) -x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{array}{ll} f\left(Q_{11}\right ) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \end{array}\right]\left[\ begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left(f\left(Q_{11}\right)\left(x_2-x\right)\ left(y_2-y\right)+f\left(Q_{21}\right)\left(x-x_1\right)\left(y_2-y\right)+f\left(Q_{12}\right) \left(x_2-x\right)\left(y-y_1\right)+f\left(Q_{22}\right)\left(x-x_1\right)\left(y-y_1\right)\right ) \\ & =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{配列}{ll} f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22} \right) \end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left(f\left(Q_{11}\right)\left(x_2-x\right)\ left(y_2-y\right)+f\left(Q_{21}\right)\left(x-x_1\right)\left(y_2-y\right)+f\left(Q_{12}\right) \left(x_2-x\right)\left(y-y_1\right)+f\left(Q_{22}\right)\left(x-x_1\right)\left(y-y_1\right)\right ) \\ & =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{配列}{ll} f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22} \right) \end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{array}{ll } f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \ end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{array}{ll } f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \ end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列}f ( x ,y )≈y2−y1y2−はいf( x ,y1)+y2−y1y−y1f( x ,y2)=y2−y1y2−はい(バツ2−バツ1バツ2−×f( Q11)+バツ2−バツ1バツ−バツ1f( Q21) )+y2−y1y−y1(バツ2−バツ1バツ2−×f( Q12)+バツ2−バツ1バツ−バツ1f( Q22) )=( ×2−バツ1)( y2−y1)1( f( Q11)( ×2−× )( y2−y )+f( Q21)( ×−バツ1)( y2−y )+f( Q12)( ×2−× )( y−y1)+f( Q22)( ×−バツ1)( y−y1) )=( ×2−バツ1)( y2−y1)1[ ×2−バツバツ−バツ1】[f( Q11)f( Q21)f( Q12)f( Q22)】[y2−yy−y1】.
最初にy方向、次にx方向
yyの最初y方向の線形補間yyyが変化すると、xxx不変)、
f ( x 1 , y ) ≈ y 2 − yy 2 − y 1 f ( Q 11 ) + y − y 1 y 2 − y 1 f ( Q 12 ) , f ( x 2 , y ) を得る≈ y 2 − yy 2 − y 1 f ( Q 21 ) + y − y 1 y 2 − y 1 f ( Q 22 ) 。\begin{aligned} & f\left(x_1, y\right) \about \frac{y_2-y}{y_2-y_1} f\left(Q_{11}\right)+\frac{y-y_1}{ y_2-y_1} f\left(Q_{12}\right), \\ & f\left(x_2, y\right) \about \frac{y_2-y}{y_2-y_1} f\left(Q_{21 }\right)+\frac{y-y_1}{y_2-y_1} f\left(Q_{22}\right) 。\end{整列}f( ×1、y )≈y2−y1y2−はいf( Q11)+y2−y1y−y1f( Q12)、f( ×2、y )≈y2−y1y2−はいf( Q21)+y2−y1y−y1f( Q22).
それからxx時にx方向に線形補間を実行して、
f ( x , y ) ≈ x 2 − xx 2 − x 1 f ( x 1 , y ) + x − x 1 x 2 − x 1 f ( x 2 , y ) = x 2 − xx 2 − x 1 ( y 2 − yy 2 − y 1 f ( Q 11 ) + y − y 1 y 2 − y 1 f ( Q 12 ) ) + x − x 1 x 2 − x 1 ( y 2 − yy 2 − y 1 f ( Q 21 ) + y − y 1 y 2 − y 1 f ( Q 22 ) ) = 1 ( x 2 − x 1 ) ( y 2 − y 1 ) ( 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 ) ) = 1 ( x 2 − x 1 ) ( y 2 − y 1 ) [ x 2 − xx − x 1 ] [ f ( Q 11 ) f ( Q 12 ) f ( Q 21 ) f ( Q 22 ) ] [ y 2 − yy − y 1 ] 。\begin{aligned} f(x, y) & \about \frac{x_2-x}{x_2-x_1} f\left(x_1, y\right)+\frac{x-x_1}{x_2-x_1} f \left(x_2, y\right) \\ & =\frac{x_2-x}{x_2-x_1}\left(\frac{y_2-y}{y_2-y_1} f\left(Q_{11}\right)+\frac{y-y_1}{y_2- y_1} f\left(Q_{12}\right)\right)+\frac{x-x_1}{x_2-x_1}\left(\frac{y_2-y}{y_2-y_1} f\left(Q_{ 21}\right)+\frac{y-y_1}{y_2-y_1} f\left(Q_{22}\right)\right) \\ & =\frac{1}{\left(x_2-x_1\right) )\left(y_2-y_1\right)}\left(f\left(Q_{11}\right)\left(x_2-x\right)\left(y_2-y\right)+f\left(Q_{ 21}\right)\left(x-x_1\right)\left(y_2-y\right)+f\left(Q_{12}\right)\left(x_2-x\right)\left(y-y_1 \right)+f\left(Q_{22}\right)\left(x-x_1\right)\left(y-y_1\right)\right) \\ & =\frac{1}{\left(x_2) -x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{array}{ll} f\left(Q_{11}\right ) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \end{array}\right]\left[\ begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left(f\left(Q_{11}\right)\left(x_2-x\right)\ left(y_2-y\right)+f\left(Q_{21}\right)\left(x-x_1\right)\left(y_2-y\right)+f\left(Q_{12}\right) \left(x_2-x\right)\left(y-y_1\right)+f\left(Q_{22}\right)\left(x-x_1\right)\left(y-y_1\right)\right ) \\ & =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{配列}{ll} f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22} \right) \end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left(f\left(Q_{11}\right)\left(x_2-x\right)\ left(y_2-y\right)+f\left(Q_{21}\right)\left(x-x_1\right)\left(y_2-y\right)+f\left(Q_{12}\right) \left(x_2-x\right)\left(y-y_1\right)+f\left(Q_{22}\right)\left(x-x_1\right)\left(y-y_1\right)\right ) \\ & =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{配列}{ll} f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22} \right) \end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{array}{ll } f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \ end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列} =\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\right]\left[\begin{array}{ll } f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \ end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。\end{整列}f ( x ,y )≈バツ2−バツ1バツ2−×f( ×1、y )+バツ2−バツ1バツ−バツ1f( ×2、y )=バツ2−バツ1バツ2−×(y2−y1y2−はいf( Q11)+y2−y1y−y1f( Q12) )+バツ2−バツ1バツ−バツ1(y2−y1y2−はいf( Q21)+y2−y1y−y1f( Q22) )=( ×2−バツ1)( y2−y1)1( f( Q11)( ×2−× )( y2−y )+f( Q21)( ×−バツ1)( y2−y )+f( Q12)( ×2−× )( y−y1)+f( Q22)( ×−バツ1)( y−y1) )=( ×2−バツ1)( y2−y1)1[ ×2−バツバツ−バツ1】[f( Q11)f( Q21)f( Q12)f( Q22)】[y2−yy−y1】.
どちらの方向が最初に補間されても、双一次補間の結果は同じであることがわかります。
簡略化された双一次補間
ffのような座標系を選択すると、fの 4 つの既知の点の座標は、( x 1 , y 1 ) = ( 0 , 0 )、( x 1 , y 2 ) = ( 0 , 1 )、( x 2 , y 1 ) = ( 1 , 0) です。) (x_1,y_1)=(0,0)、(x_1,y_2)=(0,1)、(x_2,y_1)=(1,0)( ×1、y1)=( 0 ,0 ) 、( ×1、y2)=( 0 ,1 ) 、( ×2、y1)=( 1 、0 )和( x 2 , y 2 ) = ( 1 , 1 ) (x_2,y_2)=(1,1)( ×2、y2)=( 1 、1 )、那么插值公式は可能化可能です
f ( x , y ) ≈ f ( 0 , 0 ) ( 1 − x ) ( 1 − y ) + f ( 1 , 0 ) x ( 1 − y ) + f ( 0 , 1 ) ( 1 − x ) y + f ( 1 , 1 ) xy ≈ [ 1 − xx ] [ f ( 0 , 0 ) f ( 0 , 1 ) f ( 1 , 0 ) f ( 1 , 1 ) ] [ 1 − yy ] \begin{aligned} f(x, y) &\およそ f(0,0)(1-x)(1-y)+f(1,0) x(1-y)+f (0,1)(1-x) y+f(1,1) xy \\ & \about\left[\begin{array}{ll} 1-x & x \end{array}\right]\left [\begin{配列}{ll} f(0,0) & f(0,1) \\ f(1,0) & f(1,1) \end{配列}\right]\left[\begin {配列}{c} 1-y \\ y \end{配列}\right] \end{aligned}f ( x ,y )≈f ( 0 ,0 ) ( 1−x ) ( 1−y )+f ( 1 ,0 ) x ( 1−y )+f ( 0 ,1 ) ( 1−x ) y+f ( 1 ,1 ) x y≈[1−××】[f ( 0 ,0 )f ( 1 ,0 )f ( 0 ,1 )f ( 1 ,1 )】[1−yはい]
双一次補間の一次導関数
コード読み取りを行うと、x 方向と y 方向の補間結果の一次微分を計算する必要がある場合があるため、ここでは双線形補間の一次微分も与えます。
f ( x , y ) f(x,y)f ( x ,y ) xxでx方向の 1 つ:
∂ f ∂ x = 1 ( x 2 − x 1 ) ( y 2 − y 1 ) [ − 1 1 ] [ f ( Q 11 ) f ( Q 12 ) f ( Q 21 ) f (Q 22 ) ] [ y 2 − yy − y 1 ] 。\frac{\partial f}{\partial x}=\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[-1 \quad 1\right]\ left[\begin{array}{ll} f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left (Q_{22}\right) \end{array}\right]\left[\begin{array}{l} y_2-y \\ y-y_1 \end{array}\right] 。∂ ×∂f _=( ×2−バツ1)( y2−y1)1[ − 11 ][f( Q11)f( Q21)f( Q12)f( Q22)】[y2−yy−y1】。
f ( x , y ) f(x,y)f ( x ,y )在yyy方向の一次導関数
∂ f ∂ y = 1 ( x 2 − x 1 ) ( y 2 − y 1 ) [ x 2 − xx − x 1 ] [ f ( Q 11 ) f ( Q 12 ) f ( Q 21 ) f ( Q 22 ) ] [ − 1 1 ] 。\frac{\partial f}{\partial y}=\frac{1}{\left(x_2-x_1\right)\left(y_2-y_1\right)}\left[x_2-x \quad x-x_1\ right]\left[\begin{array}{ll} f\left(Q_{11}\right) & f\left(Q_{12}\right) \\ f\left(Q_{21}\right) & f\left(Q_{22}\right) \end{array}\right]\left[\begin{array}{l} -1 \\ 1 \end{array}\right] 。∂y _∂f _=( ×2−バツ1)( y2−y1)1[ ×2−バツバツ−バツ1】[f( Q11)f( Q21)f( Q12)f( Q22)】[− 11】。
簡略化:
∂ f ∂ x = [ − 1 , 1 ] [ f ( 0 , 0 ) f ( 0 , 1 ) f ( 1 , 0 ) f ( 1 , 1 ) ] [ 1 − yy ] \frac{\partial f}{ \partial x}=[-1,1]\left[\begin{array}{ll} f(0,0) & f(0,1) \\ f(1,0) & f(1,1) \end{配列}\right]\left[\begin{配列}{c} 1-y \\ y \end{配列}\right]∂ ×∂f _=[ − 1 、1 ][f ( 0 ,0 )f ( 1 ,0 )f ( 0 ,1 )f ( 1 ,1 )】[1−yはい】
∂ f ∂ y = [ 1 − x , x ] [ f ( 0 , 0 ) f ( 0 , 1 ) f ( 1 , 0 ) f ( 1 , 1 ) ] [ − 1 1 ] \frac{\partial f} {\partial y}=[1-x, x]\left[\begin{array}{ll} f(0,0) & f(0,1) \\ f(1,0) & f(1, 1) \end{配列}\right]\left[\begin{配列}{c} -1 \\ 1 \end{配列}\right]∂y _∂f _=[ 1−× 、× ][f ( 0 ,0 )f ( 1 ,0 )f ( 0 ,1 )f ( 1 ,1 )】[− 11】
C++ 実装リファレンスは次のとおりです。