Shape-Preserving Half-Projective Warps for Image Stitching(SPHP)

SPHP

通过特征匹配估计一个重叠区域的homography,并平滑过度到非重叠区域的相似变换,使得重叠区域有一个感官自然的视角。

1.分析投影变换

投影变换(单应性矩阵)表示像素点 在齐次坐标系下的线性变换关系:
[ x ′ y ′ 1 ] ∼ [ h ^ 1 h ^ 2 h ^ 3 h ^ 4 h ^ 5 h ^ 6 h ^ 7 h ^ 8 1 ] [ x y 1 ] , \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1\end{array}\right] \sim \left[\begin{array}{ccc} \hat{h}_{1} & \hat{h}_{2} & \hat{h}_{3} \\ \hat{h}_{4} & \hat{h}_{5} & \hat{h}_{6} \\ \hat{h}_{7} & \hat{h}_{8} & 1 \end{array}\right] \left[\begin{array}{c} x \\ y \\ 1\end{array}\right], xy1h^1h^4h^7h^2h^5h^8h^3h^61xy1,
x ′ = h ^ 1 x + h ^ 2 y + h ^ 3 h ^ 7 x + h ^ 8 y + 1 , y ′ = h ^ 4 x + h ^ 5 y + h ^ 6 h ^ 7 x + h ^ 8 y + 1 . x^{\prime}=\frac{\hat{h}_{1} x+\hat{h}_{2} y+\hat{h}_{3}}{\hat{h}_{7} x+\hat{h}_{8} y+1}, \quad y^{\prime}=\frac{\hat{h}_{4} x+\hat{h}_{5} y+\hat{h}_{6}}{\hat{h}_{7} x+\hat{h}_{8} y+1} . x=h^7x+h^8y+1h^1x+h^2y+h^3,y=h^7x+h^8y+1h^4x+h^5y+h^6.
当我们将(x,y)旋转一定角度,变为新的坐标(u,v)时,有如下对应关系:
[ x y ] = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] [ u v ] , θ = atan ⁡ 2 ( − h ^ 8 , − h ^ 7 ) . \begin{aligned} {\left[\begin{array}{l} x \\ y \end{array}\right] } &=\left[\begin{array}{cc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right]\left[\begin{array}{l} u \\ v \end{array}\right], \\ \theta &=\operatorname{atan} 2\left(-\hat{h}_{8},-\hat{h}_{7}\right) . \end{aligned} [xy]θ=[cosθsinθsinθcosθ][uv],=atan2(h^8,h^7).
进行坐标变换后,新的单应矩阵可以表示为:
[ x ′ y ′ 1 ] ∼ [ h 1 h 2 h 3 h 4 h 5 h 6 − c 0 1 ] [ u v 1 ] ,  where  [ h 1 h 2 h 4 h 5 ] = [ h ^ 1 h ^ 2 h ^ 4 h ^ 5 ] [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] , ( h 3 , h 6 ) = ( h ^ 3 , h ^ 8 ) , c = h ^ 7 2 + h ^ 8 2 . \begin{array}{r} {\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right] \sim\left[\begin{array}{lll} h_{1} & h_{2} & h_{3} \\ h_{4} & h_{5} & h_{6} \\ -c & 0 & 1 \end{array}\right]\left[\begin{array}{l} u \\ v \\ 1 \end{array}\right],} \\ \text { where }\left[\begin{array}{ll} h_{1} & h_{2} \\ h_{4} & h_{5} \end{array}\right]=\left[\begin{array}{ll} \hat{h}_{1} & \hat{h}_{2} \\ \hat{h}_{4} & \hat{h}_{5} \end{array}\right]\left[\begin{array}{cc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right], \\ \left(h_{3}, h_{6}\right)=\left(\hat{h}_{3}, \hat{h}_{8}\right), \\ c=\sqrt{\hat{h}_{7}^{2}+\hat{h}_{8}^{2}} . \end{array} xy1h1h4ch2h50h3h61uv1, where [h1h4h2h5]=[h^1h^4h^2h^5][cosθsinθsinθcosθ],(h3,h6)=(h^3,h^8),c=h^72+h^82 .
新的映射可以写为:
x ′ = H x ( u , v ) = h 1 u + h 2 v + h 3 1 − c u y ′ = H y ( u , v ) = h 4 u + h 5 v + h 6 1 − c u \begin{array}{l} x^{\prime}=H_{x}(u, v)=\frac{h_{1} u+h_{2} v+h_{3}}{1-c u} \\ y^{\prime}=H_{y}(u, v)=\frac{h_{4} u+h_{5} v+h_{6}}{1-c u} \end{array} x=Hx(u,v)=1cuh1u+h2v+h3y=Hy(u,v)=1cuh4u+h5v+h6

将图片旋转一定的角度到u,v坐标系下时, 映射函数H的分母只会和u有关,便于分析投影变换函数的物理意义。------函数换元

1.1 H的尺度变换

其中H可以分解为一个仿射变换 H A H_A HA和一个纯投影变换 H P H_P HP
[ h 1 h 2 h 3 h 4 h 5 h 6 − c 0 1 ] ⏟ H = [ h 1 + c h 3 h 2 h 3 h 4 + c h 6 h 5 h 6 0 0 1 ] ⏟ H A [ 1 0 0 0 1 0 − c 0 1 ] ⏟ H P . \underbrace{\left[\begin{array}{ccc} h_{1} & h_{2} & h_{3} \\ h_{4} & h_{5} & h_{6} \\ -c & 0 & 1 \end{array}\right]}_{H}=\underbrace{\left[\begin{array}{ccc} h_{1}+c h_{3} & h_{2} & h_{3} \\ h_{4}+c h_{6} & h_{5} & h_{6} \\ 0 & 0 & 1 \end{array}\right]}_{H_{A}} \underbrace{\left[\begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ -c & 0 & 1 \end{array}\right]}_{H_{P}} . H h1h4ch2h50h3h61=HA h1+ch3h4+ch60h2h50h3h61HP 10c010001.

像素点u,v到参考坐标系 x ′ , y ′ x',y' x,y的局部变换可以用单应性矩阵H的雅克比矩阵的行列式表示:
det ⁡ J ( u , v ) = det ⁡ J A ( u , v ) ⋅ det ⁡ J P ( u , v ) = s A ⋅ 1 ( 1 − c u ) 3 \begin{aligned} \operatorname{det} J(u, v) &=\operatorname{det} J_{A}(u, v) \cdot \operatorname{det} J_{P}(u, v) \\ &=s_{A} \cdot \frac{1}{(1-c u)^{3}} \end{aligned} detJ(u,v)=detJA(u,v)detJP(u,v)=sA(1cu)31

其中 S A = d e t J A ( u , v ) S_A=detJ_A(u,v) SA=detJA(u,v)是取决于u和v的常量。局部变换尺度因子只取决于u,u越大,H导致的尺度变换就越大,

雅克比矩阵是泰勒展开公式一阶导数的前面的系数,在二维坐标变换中,雅可比矩阵揭露着不同微元之间的关系。其行列式值代表二维面积 的比例。代表了沿着u轴图像会逐渐拉伸。

1.2 H的线性

仿射变换保留线长度比例,然而投影变换并不会。在特定坐标下,长度比例在投影变换下也可以被正确保留,在下面式子中
x ′ = H x ( u 0 , v ) = h 2 1 − c u 0 v + h 1 u 0 + h 3 1 − c u 0 y ′ = H y ( u 0 , v ) = h 5 1 − c u 0 v + h 4 u 0 + h 0 1 − c u 0 \begin{array}{l} x^{\prime}=H_{x}\left(u_{0}, v\right)=\frac{h_{2}}{1-c u_{0}} v+\frac{h_{1} u_{0}+h_{3}}{1-c u_{0}} \\ y^{\prime}=H_{y}\left(u_{0}, v\right)=\frac{h_{5}}{1-c u_{0}} v+\frac{h_{4} u_{0}+h_{0}}{1-c u_{0}} \end{array} x=Hx(u0,v)=1cu0h2v+1cu0h1u0+h3y=Hy(u0,v)=1cu0h5v+1cu0h4u0+h0

如果固定u的值,长度Hx和Hy都是v的线性函数,因此长度比例会保留。

即图像纵轴平行于v的轴上所有点变换后,依然会保持比例,不会造成失真。

1.3规则的边界

规则的边界是通过移动直线扫出来的,可以参数化表示为: S ( u , v ) = p ( u ) + v ∗ r ( u ) S(u,v) = p(u) + v*r(u) S(u,v)=p(u)+vr(u),其中p(u)为基准曲线,r(u)是导向曲线,考虑函数
[ u v k ( u , v ) ] = [ u 0 g ( u ) ] ⏟ p ( u ) + [ 0 1 f ( u ) ] ⏟ r ( u ) v \left[\begin{array}{c} u \\ v \\ k(u, v) \end{array}\right]=\underbrace{\left[\begin{array}{c} u \\ 0 \\ g(u) \end{array}\right]}_{\mathbf{p}(u)}+\underbrace{\left[\begin{array}{c} 0 \\ 1 \\ f(u) \end{array}\right]}_{\mathbf{r}(u)}v uvk(u,v)=p(u) u0g(u)+r(u) 01f(u)v
H也可以写成上面形式表示图为规则表面。
Shape-Preserving Half-Projective Warps for Image Stitching(SPHP)_第1张图片

上面分析一大堆,就是为了说明投影变换产生上图形状,当旋转一定角度,图像沿着u轴继续变换会造成拉伸,但垂直线的长度比不变。且产生规则的变化

2. 半投影变换
半投影保持变换,主要思想将图像划分三个部分,第一部分采用投影变换H,第三部分是一个相似变换S,第二部分是一个缓冲区通过变换T让投影变换过渡到相似变换,以至于不会产生太大的突变。

要保证图像在分界线 u 1 u_1 u1处所有 S ( u , v ) = H ( u , v ) S(u,v)=H(u,v) S(u,v)=H(u,v)
S ( u , v ) = 1 1 − c u 1 ( [ h 5 h 2 − h 2 h 5 ] [ u v ] + [ ( h 1 − h 5 ) u 1 + h 3 ( h 4 + h 2 ) u 1 + h 6 ] ) . S(u, v)=\frac{1}{1-c u_{1}}\left(\left[\begin{array}{cc} h_{5} & h_{2} \\ -h_{2} & h_{5} \end{array}\right]\left[\begin{array}{l} u \\ v \end{array}\right]+\left[\begin{array}{l} \left(h_{1}-h_{5}\right) u_{1}+h_{3} \\ \left(h_{4}+h_{2}\right) u_{1}+h_{6} \end{array}\right]\right) . \\ S(u,v)=1cu11([h5h2h2h5][uv]+[(h1h5)u1+h3(h4+h2)u1+h6]).
S ( u , v ) = [ S z ( u , v ) S y ( u , v ) ] = [ α − β β α ] [ u v ] + [ t x t y ] S(u, v)=\left[\begin{array}{l} S_{z}(u, v) \\ S_{y}(u, v) \end{array}\right]=\left[\begin{array}{cc} \alpha & -\beta \\ \beta & \alpha \end{array}\right]\left[\begin{array}{l} u \\ v \end{array}\right]+\left[\begin{array}{l} t_{x} \\ t_{y} \end{array}\right] S(u,v)=[Sz(u,v)Sy(u,v)]=[αββα][uv]+[txty]

u,v到x’,y’ 的变换H写成相似变换矩阵的形式只能是上式,即相当于确定了u1后就能确定相似变换S满足在u1处S=H

假设中间过渡变换T为
T ( u , v ) = [ T x ( u , v ) T y ( u , v ) ] = v [ f x ( u ) f y ( u ) ] + [ g x ( u ) g y ( u ) ] . T(u, v)=\left[\begin{array}{l} T_{x}(u, v) \\ T_{y}(u, v) \end{array}\right]=v \left[\begin{array}{l} f_{x}(u) \\ f_{y}(u) \end{array}\right]+\left[\begin{array}{l} g_{x}(u) \\ g_{y}(u) \end{array}\right] . T(u,v)=[Tx(u,v)Ty(u,v)]=v[fx(u)fy(u)]+[gx(u)gy(u)].
为了保证还是规则曲线,总的变换w可以写成
w ( u , v ) = [ w x ( u , v ) w y ( u , v ) ] = [ F x ( u ) v + G x ( u ) F y ( u ) v + G y ( u ) ] w(u, v)=\left[\begin{array}{l} w_{x}(u, v) \\ w_{y}(u, v) \end{array}\right]=\left[\begin{array}{c} F_{x}(u) v+G_{x}(u) \\ F_{y}(u) v+G_{y}(u) \end{array}\right] w(u,v)=[wx(u,v)wy(u,v)]=[Fx(u)v+Gx(u)Fy(u)v+Gy(u)]
其中F和G
F x ( u ) = { h 2 1 − c u  if  u ≤ u 1 f x ( u )  if  u 1 < u < u 2 − β  if  u 2 ≤ u G x ( u ) = { h 1 u + h 3 1 − c u  if  u ≤ u 1 g x ( u )  if  u 1 < u < u 2 α u + t x  if  u 2 ≤ u \begin{array}{l} F_{x}(u)=\left\{\begin{array}{ll} \frac{h_{2}}{1-c u} & \text { if } u \leq u_{1} \\ f_{x}(u) & \text { if } u_{1}Fx(u)=1cuh2fx(u)β if uu1 if u1<u<u2 if u2uGx(u)=1cuh1u+h3gx(u)αu+tx if uu1 if u1<u<u2 if u2u
接下来求 α 、 β 、 t x 、 t y 、 f x 、 f y 、 g x 、 g y \alpha、\beta、t_x、t_y、f_x、f_y、g_x、g_y αβtxtyfxfygxgy等参数,我们需要w是连续的即F和G是连续的。根据连续的定义。
f x ( u 1 ) = h 2 1 − c u 1 ( F x ( u 1 )  is continuous  ) f x ′ ( u 1 ) = c h 2 ( 1 − c u 1 ) 2 ( F x ′ ( u 1 )  is continuous  ) f x ( u 2 ) = − β ( F x ( u 2 )  is continuous  ) f x ′ ( u 2 ) = 0 ( F x ′ ( u 2 )  is continuous  ) \begin{array}{ll} f_{x}\left(u_{1}\right)=\frac{h_{2}}{1-c u_{1}} & \left(F_{x}\left(u_{1}\right) \text { is continuous }\right) \\ f_{x}^{\prime}\left(u_{1}\right)=\frac{c h_{2}}{\left(1-c u_{1}\right)^{2}} & \left(F_{x}^{\prime}\left(u_{1}\right) \text { is continuous }\right) \\ f_{x}\left(u_{2}\right)=-\beta & \left(F_{x}\left(u_{2}\right) \text { is continuous }\right) \\ f_{x}^{\prime}\left(u_{2}\right)=0 & \left(F_{x}^{\prime}\left(u_{2}\right) \text { is continuous }\right) \end{array} fx(u1)=1cu1h2fx(u1)=(1cu1)2ch2fx(u2)=βfx(u2)=0(Fx(u1) is continuous )(Fx(u1) is continuous )(Fx(u2) is continuous )(Fx(u2) is continuous )
当u1和u2确定可以求得对应的过渡区变换矩阵。

当u1和u2确定时,首先相似变换很容易确定,然后最重要的过渡区变换,过渡区变换需要确定很多参数,可以相似和透视变换矩阵求出。依据是在u1和u2处函数连续。–高数

3. u1和u2确定

给定两幅图像为了保形我们肯定需要相似变换的区域越大越好。我们有
E i ( u 1 , u 2 ) = min ⁡ a i , b i ∬ ( x , y ) ∈ Ω i ∥ J i ( x , y ; u 1 , u 2 ) − [ a i − b i b i a i ] ∥ F 2 d x d y \begin{array}{l} E_{i}\left(u_{1}, u_{2}\right) \\ =\min _{a_{i}, b_{i}} \iint_{(x, y) \in \Omega_{i}}\left\|J_{i}\left(x, y ; u_{1}, u_{2}\right)-\left[\begin{array}{cc} a_{i} & -b_{i} \\ b_{i} & a_{i} \end{array}\right]\right\|_{F}^{2} d x d y \end{array} Ei(u1,u2)=minai,bi(x,y)ΩiJi(x,y;u1,u2)[aibibiai]F2dxdy
I i I_i Ii中的区域内,其中J代表着w扭曲在xy出的雅克比矩阵,可以通过u1 和u2 确定, 后面是一个最接近的相似变换。

你可能感兴趣的:(图像处理,线性代数,矩阵,几何学)