初学图像处理,如有写的不正确的地方请多纠正
图像的平移
图像平移(Translation)是将图像中所有的点都按照指定的平移量,进行水平、垂直移动。
假设图像某一点像素 ( x , y ) (x,y) (x,y),向图像坐标轴X方向上移动 Δ \Delta Δx,向图像坐标轴Y轴方向上移动 Δ \Delta Δy,移动到点 ( M , N ) (M,N) (M,N)。
方程组表示
{ M = x + Δ x N = y + Δ y (0) \begin{cases} M = x + \Delta x\\ N = y + \Delta y\\ \end{cases}\tag{0} { M=x+ΔxN=y+Δy(0)
矩阵表示
[ M N 1 ] = [ 1 0 Δ x 0 1 Δ y 0 0 1 ] [ x y 1 ] (1) \begin{gathered} \begin{bmatrix}M\\N\\1\end{bmatrix} =\begin{bmatrix}1 & 0 & \Delta x \\0 & 1 & \Delta y \\0& 0& 1\end{bmatrix} \begin{bmatrix}x \\y \\1\end{bmatrix} \end{gathered}\tag{1} ⎣⎡MN1⎦⎤=⎣⎡100010ΔxΔy1⎦⎤⎣⎡xy1⎦⎤(1)
图像的旋转
必须指明图像绕着什么旋 转。一般图像的旋转是以图 像的中心为原点,旋转一定 的角度。 旋转后,一般会改变图像的大小。
A旋转到B
方程组表示
{ x = R ∗ s i n α y = R ∗ c o s α ; { M = R ∗ s i n ( α + β ) = R ( s i n α c o s β + s i n β c o s α ) = x c o s β + y s i n β N = R ∗ c o s ( α + β ) = R ( c o s α c o s β − s i n β s i n α ) = − x s i n β + y c o s β ; (0) \begin{gathered} \begin{cases} x= R*sin\alpha\\ y =R*cos\alpha \end{cases} ;&& \begin{cases} M= R*sin(\alpha + \beta) =R(sin\alpha cos\beta+ sin\beta cos\alpha) = xcos\beta + ysin\beta \\ N =R*cos(\alpha + \beta)=R(cos\alpha cos\beta - sin\beta sin\alpha) = - xsin\beta+ycos\beta \end{cases} ;\tag{0} \end{gathered} { x=R∗sinαy=R∗cosα;{ M=R∗sin(α+β)=R(sinαcosβ+sinβcosα)=xcosβ+ysinβN=R∗cos(α+β)=R(cosαcosβ−sinβsinα)=−xsinβ+ycosβ;(0)
矩阵表示
[ M N 1 ] = [ c o s β s i n β 0 − s i n β c o s β 0 0 0 1 ] [ x y 1 ] (1) \begin{gathered} \begin{bmatrix}M\\N\\1\end{bmatrix} =\begin{bmatrix}cos\beta & sin\beta & 0 \\-sin\beta & cos\beta & 0 \\0& 0& 1\end{bmatrix} \begin{bmatrix}x \\y \\1\end{bmatrix} \end{gathered}\tag{1} ⎣⎡MN1⎦⎤=⎣⎡cosβ−sinβ0sinβcosβ0001⎦⎤⎣⎡xy1⎦⎤(1)
图像的缩放
假设图像X轴方向缩放比率是k1,Y轴方向缩放比率是k2。
方程组表示
{ M = x ∗ K 1 N = y ∗ K 2 \begin{cases} M=x*K1\\ N =y*K2 \end{cases} { M=x∗K1N=y∗K2
矩阵表示
[ M N 1 ] = [ K 1 0 0 0 K 2 0 0 0 1 ] [ x y 1 ] (1) \begin{gathered} \begin{bmatrix}M\\N\\1\end{bmatrix} =\begin{bmatrix}K1 & 0 & 0 \\0 & K2 & 0 \\0& 0& 1\end{bmatrix} \begin{bmatrix}x \\y \\1\end{bmatrix} \end{gathered}\tag{1} ⎣⎡MN1⎦⎤=⎣⎡K1000K20001⎦⎤⎣⎡xy1⎦⎤(1)
图像放大
当kx>1且ky>1时,原图像被放大,面积增加。由于放大图像时产生了新的像素,可通过插值算法来近似处理。
当kx=ky=2时,图像放大2倍,原图中的某一个像素,对应新图的4个像素。
[ 1 2 3 4 2 3 4 0 5 6 7 7 6 6 3 3 ] − > [ 1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4 2 2 3 3 4 4 0 0 2 2 3 3 4 4 0 0 5 5 6 6 7 7 7 7 5 5 6 6 7 7 7 7 6 6 6 6 3 3 3 3 6 6 6 6 3 3 3 3 ] (1) \begin{gathered} \begin{bmatrix} 1&2&3&4\\ 2&3&4&0\\ 5&6&7&7\\ 6&6&3&3 \end{bmatrix} -> \begin{bmatrix} 1&1&2&2&3&3&4&4\\ 1&1&2&2&3&3&4&4\\ 2&2&3&3&4&4&0&0\\ 2&2&3&3&4&4&0&0\\ 5&5&6&6&7&7&7&7\\ 5&5&6&6&7&7&7&7\\ 6&6&6&6&3&3&3&3\\ 6&6&6&6&3&3&3&3 \end{bmatrix} \end{gathered}\tag{1} ⎣⎢⎢⎡1256236634734073⎦⎥⎥⎤−>⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎡1122556611225566223366662233666633447733334477334400773344007733⎦⎥⎥⎥⎥⎥⎥⎥⎥⎥⎥⎤(1)
图像缩小
当kx<1且ky<1时,原图像被缩小。
当kx=ky=0.5时,被缩小一半。
原图中4个像素对应新图中的一个像素。 此时缩小后的图像中的(0,0)像素对 应于原图中的(0,0)、(0,1)、(1, 0)、(1,1)像素。
图像的转置
将图像像素的x坐标和y坐标 互换。将改变图像的高度和宽度,转置后图像的高度和宽度将互换。
方程组表示
{ x = y 0 y = x 0 (0) \begin{cases} x = y0\\ y= x0\\ \end{cases}\tag{0} {
x=y0y=x0(0)
矩阵表示
[ x y 1 ] = [ 1 0 0 0 1 0 0 0 1 ] [ y 0 x 0 1 ] (1) \begin{gathered} \begin{bmatrix}x\\y\\1\end{bmatrix} =\begin{bmatrix}1 & 0 & 0\\0 & 1 & 0 \\0& 0& 1\end{bmatrix} \begin{bmatrix}y0 \\x0 \\1\end{bmatrix} \end{gathered}\tag{1} ⎣⎡xy1⎦⎤=⎣⎡100010001⎦⎤⎣⎡y0x01⎦⎤(1)
图像的镜像变换
图像的镜像变换分为两种:一种是水平镜像,另一种是垂直镜像。镜像变换后图的高和宽都不变。
图像的水平镜像操作
是以原图像的垂直中轴线为中心,将图像分为左右两部分进行对称变换;
设图像高度为Height,宽度为Width,原图中的(x0,y0)经过水平镜像后,坐标将变成(Width-x0,y0)。
方程组表示
{ x = W i d t h − x 0 y = y 0 (0) \begin{cases} x = Width - x0\\ y= y0\\ \end{cases}\tag{0} { x=Width−x0y=y0(0)
矩阵表示
[ x y 1 ] = [ − 1 0 W i d t h 0 1 0 0 0 1 ] [ x 0 y 0 1 ] (1) \begin{gathered} \begin{bmatrix}x\\y\\1\end{bmatrix} =\begin{bmatrix}-1 & 0 & Width \\0 & 1 & 0 \\0& 0& 1\end{bmatrix} \begin{bmatrix}x0 \\y0 \\1\end{bmatrix} \end{gathered}\tag{1} ⎣⎡xy1⎦⎤=⎣⎡−100010Width01⎦⎤⎣⎡x0y01⎦⎤(1)
交换像素值。
图像的垂直镜像操作
是以原图像的水平中轴线为中心,将图像分为上下两部分进行对称变换。
点(x0,y0)经过垂直镜像后,坐标将变成为(x0,Height-y0)。
方程组表示
{ x = x 0 y = H e i g h t − y 0 (0) \begin{cases} x = x0\\ y= Height - y0\\ \end{cases}\tag{0} { x=x0y=Height−y0(0)
矩阵表示
[ x y 1 ] = [ − 1 0 0 0 − 1 H e i g h t 0 0 1 ] [ x 0 y 0 1 ] (1) \begin{gathered} \begin{bmatrix}x\\y\\1\end{bmatrix} =\begin{bmatrix}-1 & 0 & 0 \\0 & -1 & Height \\0& 0& 1\end{bmatrix} \begin{bmatrix}x0 \\y0 \\1\end{bmatrix} \end{gathered}\tag{1} ⎣⎡xy1⎦⎤=⎣⎡−1000−100Height1⎦⎤⎣⎡x0y01⎦⎤(1)