图像变换与平面坐标系的关系

转载自:

[1] http://blog.csdn.net/tangyongkang

[2]https://zhuanlan.zhihu.com/p/74597564

 

坐标旋转变换公式(围绕原点)

 

如图, 在二维坐标上,有一点p(x, y), 直线 op 的长度为r, 直线 op  和 x 轴的正向的夹角为a。 直线 op  围绕原点做逆时针方向 b度的旋转,到达{p}'(s,t)

那么有:

s = r cos(a + b) = r cos(a)cos(b) - r sin(a)sin(b)   (1.1)
t = r sin(a + b) = r sin(a)cos(b) + r cos(a) sin(b)   (1.2)

其中x = r cos(a) , y = r sin(a)
代入(1.1), (1.2) ,
\\s = x cos(b) - y sin(b) \\ t = x sin(b) + y cos(b)

用行列式表达如下:

{\color{Blue} \begin{bmatrix} s \\t \end{bmatrix} = \begin{bmatrix} cos\theta & -sin \theta\\ sin\theta &cos\theta \end{bmatrix}\begin{bmatrix} x \\y \end{bmatrix} }

综上:

将图形围绕原点(0,0)逆时针方向旋转 \theta 角,用解析式表示为:

\\x' =x \cdot \text{cos}\theta-y\cdot\text{sin}\theta \\ y' =x \cdot \text{sin}\theta+y\cdot\text{cos}\theta \\

写成矩阵乘法形式:

\begin{pmatrix} x' \\ y' \\ \end{pmatrix} = \begin{bmatrix} \text{cos}\theta & -\text{sin}\theta \\ \text{sin}\theta & \text{cos}\theta \\ \end{bmatrix} \begin{pmatrix} x \\ y \\ \end{pmatrix}= R \begin{pmatrix} x \\ y\\ \end{pmatrix} \\

preview

 

平移

\\x'=x+t_x\\ y'=y+t_y\\

写成矩阵乘法形式:

\begin{pmatrix} x' \\ y' \\ \end{pmatrix} =\begin{pmatrix} x \\ y\\ \end{pmatrix} +\begin{bmatrix}t_x\\t_y\end{bmatrix}\\

preview

但是现在遇到困难了,平移无法写成和上面旋转一样的矩阵乘法形式。

所以引入齐次坐标  (x,y)\Leftrightarrow(x,y,1),再写成矩阵形式:

\begin{pmatrix} x' \\ y' \\ 1 \\ \end{pmatrix} = \begin{bmatrix} 1 & 0 & t_x\\ 0 & 1 & t_y\\ 0 & 0 & 1 \\ \end{bmatrix} \begin{pmatrix} x \\ y \\ 1 \\ \end{pmatrix}=\begin{bmatrix} I_{2\times2} & T_{2\times1} \\ 0^T &1 \\ \end{bmatrix} \begin{pmatrix} x \\ y\\ 1 \\ \end{pmatrix} \\

其中,

I_{2\times2}=\begin{bmatrix} 1 &0\\0&1\end{bmatrix}表示单位矩阵,而T_{2\times1} =\begin{bmatrix}t_x\\t_y\end{bmatrix}表示平移向量。

那么就可以把把旋转平移统一写在一个矩阵乘法公式中,即刚体变换

\begin{pmatrix} x' \\ y' \\ 1 \\ \end{pmatrix} = \begin{bmatrix} \text{cos}\theta & -\text{sin}\theta & t_x\\ \text{sin}\theta & \text{cos}\theta & t_y\\ 0 & 0 & 1 \\ \end{bmatrix} \begin{pmatrix} x \\ y \\ 1 \\ \end{pmatrix}=\begin{bmatrix} R_{2\times2} & T_{2\times1} \\ 0^T &1 \\ \end{bmatrix} \begin{pmatrix} x \\ y\\ 1 \\ \end{pmatrix} \\

而旋转矩阵 R_{2\times2}=\begin{bmatrix} \cos\theta &-\sin\theta\\ \sin\theta & \cos\theta \end{bmatrix}是正交矩阵(RR^T=R^TR=\begin{bmatrix} 1 &0\\0 & 1 \end{bmatrix}).

 

刚体变换:旋转+平移(正方形-正方形)

  • 仿射变换

\begin{pmatrix} x' \\ y' \\ 1 \\ \end{pmatrix} =\begin{bmatrix} A_{2\times2} & T_{2\times1}\\ 0^T &1 \\ \end{bmatrix} \begin{pmatrix} x \\ y \\ 1 \\ \end{pmatrix} \\

其中A_{2\times2}=\begin{bmatrix} a_{11} & a_{12}\\ a_{21} & a_{22} \end{bmatrix}可以是任意2x2矩阵(与 R 一定是正交矩阵不同)。

可以看到,相比刚体变换(旋转和平移),仿射变换除了改变目标位置,还改变目标的形状,但是会保持物体的“平直性”。

不同 A 和 T 矩阵对应的各种基本仿射变换:

 

preview

  • 投影变换(单应性变换)

 

 \begin{pmatrix} x' \\ y' \\ 1 \\ \end{pmatrix} =\begin{bmatrix} A_{2\times 2} & T_{2\times1} \\ V^T &s \\ \end{bmatrix} \begin{pmatrix} x \\ y \\ 1 \\ \end{pmatrix} =H_{3\times3}\begin{pmatrix} x \\ y \\ 1 \\ \end{pmatrix}\\

preview

 简单说,投影变换彻底改变目标的形状。

总结一下:

  1. 刚体变换:平移+旋转,只改变物体位置,不改变物体形状
  2. 仿射变换:改变物体位置和形状,但是保持“平直性”
  3. 投影变换:彻底改变物体位置和形状

我们来看看完整投影变换矩阵各个参数的物理含义:

H_{3\times 3}=\begin{bmatrix} A_{2\times 2} & T_{2\times1} \\ V^T &s \\ \end{bmatrix}=\begin{bmatrix} a_{11} & a_{12} & t_x \\ a_{21} & a_{22} & t_y \\ v_1 & v_2 &s \\ \end{bmatrix} \\

A_{2\times2} 代表仿射变换参数,T_{2\times1}代表平移变换参数。V^T=[v_1,v_2]表示一种“变换后边缘交点“关系,如:

preview

至于 S 则是一个与 V^T=[v_1,v_2]相关的缩放因子。

\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ v_1 & v_2 & s \end{bmatrix} \begin{pmatrix} x \\ y \\ 1 \\ \end{pmatrix} = \begin{pmatrix} x \\ y \\ v_1x+v_2y+s \\ \end{pmatrix}\Leftrightarrow \begin{pmatrix} \frac{x}{v_1x+v_2y+s } \\ \frac{y}{v_1x+v_2y+s }\end{pmatrix} \\

一般情况下都会通过归一化使得 S = 1

 

平面坐标系与齐次坐标系

问题来了,齐次坐标到底是什么?

齐次坐标系 (x,y,w)\in \mathbb{P}^3 与常见的三维空间坐标系  (x,y,z)\in\mathbb{R}^3不同,只有两个自由度:

\begin{pmatrix} \frac{x}{w}\\ \frac{y}{w}\\ \end{pmatrix}\Leftrightarrow\begin{pmatrix} x\\ y\\ w\\ \end{pmatrix}\\

而  w(其中   w > 0)对应坐标 xy 的缩放尺度。当w = 1  时:

\begin{pmatrix} x\\ y\\ \end{pmatrix}\Leftrightarrow\begin{pmatrix} x\\ y\\ 1\\ \end{pmatrix}\\

特别的当w = 0 时,对应无穷远:

\begin{pmatrix} \text{Inf}\\ \text{Inf}\\ \end{pmatrix}\Leftrightarrow\begin{pmatrix} x\\ y\\ 0\\ \end{pmatrix}\\

 

三 单应性变换

  • 单应性是什么?

此处不经证明的给出:同一个 [无镜头畸变] 的相机从不同位置拍摄 [同一平面物体] 的图像之间存在单应性,可以用 [投影变换] 表示 。

preview

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值