图像仿射变换

仿射变换

仿射变换包括平移、旋转、缩放和错切四种基本变换的组合,广泛应用于计算机图形学、图像处理和计算机视觉等领域。

仿射变换的一般矩阵表示

二维空间中,仿射变换可以抽象表示为:

[x′y′1]=[abtxcdty001][xy1] \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =\begin{bmatrix} a & b & t_x \\ c & d & t_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} xy1=ac0bd0txty1xy1

其中,(x,y)(x,y)(x,y)是原始图像中的一个点,(x′,y′)(x′,y′)(x,y)是经过变换后的图像中的对应点。(a,b,c,d)(a,b,c,d)(a,b,c,d)描述线性变换部分,(tx,ty)(t_x,t_y)(tx,ty)用于描述平移 。

三维空间中,仿射变换可以抽象表示为:

[x′y′z′1]=[abctxdeftyghitz0001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} a & b & c & t_x \\ d & e & f & t_y \\ g & h & i & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=adg0beh0cfi0txtytz1xyz1

其中,(x,y,z)(x,y,z)(x,y,z) 是原始图像中的一个点,(x′,y′,z′)(x′,y′,z')(x,y,z) 是经过变换后的图像中的对应点。(a,b,c,d,e,f,g,h,i)(a,b,c,d,e,f,g,h,i)(a,b,c,d,e,f,g,h,i)描述线性变换部分,(tx,ty,tz)(t_x,t_y,t_z)(tx,ty,tz) 用于描述平移 。

四种基本变换的矩阵表示

1. 平移(Translation)

平移变换是指将图像中的所有点沿某个方向移动相同的距离。

二维空间矩阵表示为:

[x′y′1]=[10tx01ty001][xy1] \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} xy1=100010txty1xy1

其中,(x,y)(x,y)(x,y)是原始图像中的一个点,(x′,y′)(x′,y′)(x,y)是经过变换后的图像中的对应点。txt_xtxtyt_yty 分别是沿 x 轴和 y 轴的平移距离。

三维空间矩阵表示为:

[x′y′z′1]=[100tx010ty001tz0001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1& t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=100001000010txtytz1xyz1

其中,(x,y,z)(x,y,z)(x,y,z) 是原始图像中的一个点,(x′,y′,z′)(x′,y′,z')(x,y,z) 是经过变换后的图像中的对应点。txt_xtxtyt_ytytzt_ztz分别是沿 x 轴、 y 轴和 z 轴的平移距离。

2. 缩放(Scaling)

缩放变换用于改变图像各轴的大小。

二维空间矩阵表示为:

[x′y′1]=[sx000sy0001][xy1] \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =\begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} xy1=sx000sy0001xy1

其中,(x,y)(x,y)(x,y)是原始图像中的一个点,(x′,y′)(x′,y′)(x,y)是经过变换后的图像中的对应点。sxs_xsxsys_ysy 分别是沿 x 轴和 y 轴的缩放因子。当 sxs_xsx=sys_ysy时,图像均匀缩放。

三维空间矩阵表示为:

[x′y′z′1]=[sx0000sy0000sz00001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z& 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=sx0000sy0000sz00001xyz1

其中,(x,y,z)(x,y,z)(x,y,z) 是原始图像中的一个点,(x′,y′,z′)(x′,y′,z')(x,y,z) 是经过变换后的图像中的对应点。sxs_xsxsys_ysyszs_zsz分别是沿 x 轴、 y 轴和 z 轴的缩放因子。当 sxs_xsx=sys_ysy=szs_zsz时,图像均匀缩放。

3. 旋转(Rotation)

旋转变换是指将图像绕某个点(通常是原点)旋转一个角度。

二维空间矩阵表示为:

[x′y′1]=[cosα−sinα0sinαcosα0001][xy1] \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =\begin{bmatrix} cos α & - sin α & 0 \\ sin α & cos α & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} xy1=cosαsinα0sinαcosα0001xy1

其中,(x,y)(x,y)(x,y)是原始图像中的一个点,(x′,y′)(x′,y′)(x,y)是经过变换后的图像中的对应点。α 是旋转角度,旋转中心是图像原点,不是中心点,原点通常是左上角。

三维空间矩阵表示为:

1️⃣绕 x 轴旋转:

[x′y′z′1]=[10000cos⁡α−sin⁡α00sin⁡αcos⁡α00001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \alpha & -\sin \alpha & 0 \\ 0 & \sin \alpha & \cos \alpha & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=10000cosαsinα00sinαcosα00001xyz1

2️⃣绕 y 轴旋转:

[x′y′z′1]=[cos⁡α0sin⁡α00100−sin⁡α0cos⁡α00001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} \cos \alpha & 0 & \sin \alpha & 0 \\ 0 & 1 & 0 & 0 \\ -\sin \alpha & 0 & \cos \alpha & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=cosα0sinα00100sinα0cosα00001xyz1

3️⃣绕 z 轴旋转:

[x′y′z′1]=[cos⁡α−sin⁡α00sin⁡αcos⁡α0000100001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} \cos \alpha & -\sin \alpha & 0 & 0 \\ \sin \alpha & \cos \alpha & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=cosαsinα00sinαcosα0000100001xyz1

其中,(x,y,z)(x,y,z)(x,y,z) 是原始图像中的一个点,(x′,y′,z′)(x′,y′,z')(x,y,z) 是经过变换后的图像中的对应点。ααα是沿各轴的旋转角度。

4. 错切(Shearing)

错切变换是一种较为特殊的仿射变换,它会使图像在某个方向上发生倾斜。

二维空间矩阵表示为:

[x′y′1]=[1shx0shy10001][xy1] \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & sh_x & 0 \\ sh_y & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} xy1=1shy0shx10001xy1

其中,(x,y)(x,y)(x,y)是原始图像中的一个点,(x′,y′)(x′,y′)(x,y)是经过变换后的图像中的对应点。shxsh_xshxshysh_yshy分别是沿 x 轴和 y 轴的错切因子。

三维空间矩阵表示为:

1️⃣绕 x 轴错切:

[x′y′z′1]=[1ab0010000100001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & a & b & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=1000a100b0100001xyz1

2️⃣绕 y 轴错切:

[x′y′z′1]=[1000c1d000100001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 & 0 \\ c & 1 & d & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=1c0001000d100001xyz1

3️⃣绕 z 轴错切:

[x′y′z′1]=[10000100ef100001][xyz1] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix} =\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ e & f & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=10e001f000100001xyz1

其中,(x,y,z)(x,y,z)(x,y,z) 是原始图像中的一个点,(x′,y′,z′)(x′,y′,z')(x,y,z) 是经过变换后的图像中的对应点。(a,b,c,d,e,f)(a,b,c,d,e,f)(a,b,c,d,e,f) 是错切参数,分别控制沿不同方向的错切程度。

基本变换的组合

通过矩阵乘法,我们可以将多个基本变换组合成一个复合变换。例如,二维空间下,先平移再旋转,其复合变换矩阵为:

[x′y′1]=[cosα−sinα0sinαcosα0001][10tx01ty001][xy1] \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =\begin{bmatrix} cos α & - sin α & 0 \\ sin α & cos α & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} xy1=cosαsinα0sinαcosα0001100010txty1xy1

其中,矩阵乘法的顺序决定了符合变换的顺序,靠前的操作在右边。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开栈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值