常见的图像几何变换

您所在的位置:网站首页 图像旋转方法有哪几种 常见的图像几何变换

常见的图像几何变换

2024-07-11 22:10| 来源: 网络整理| 查看: 265

文章目录 旋转平移缩放镜像转置错切(倾斜)刚体变换相似变换仿射变换投影变换 图像的几何变换又称为图像空间变换, 它将一幅图像中的坐标位置映射到另一幅图像中的 新坐标位置。常见的几何变换包括旋转、平移、缩放、镜像、转置、错切等,以及几种组合变换,如刚体变换、仿射变换、单应变换

旋转

( x , y , ) = ( c o s ( θ ) − s i n ( θ ) s i n ( θ ) c o s ( θ ) ) ( x y ) \left(\begin{matrix} x^,\\y^, \end{matrix}\right) = \left(\begin{matrix} cos(θ) & -sin(θ)\\ sin(θ) & cos(θ) \end{matrix}\right) \left(\begin{matrix} x\\y \end{matrix}\right) (x,y,​)=(cos(θ)sin(θ)​−sin(θ)cos(θ)​)(xy​)

式中,θ表示旋转角(PS:如果是单坐标系,表示将点逆时针旋转;如果是两个坐标系转换,表示坐标系逆时针旋转,点顺时针旋转)。

M = cv2.getRotationMatrix2D((img.shape[1]*0.5, img.shape[0]*0.5), 30, 1) img_dst = cv2.warpAffine(img, M, (width, height))

在这里插入图片描述

平移

在这里插入图片描述

M = np.float32([[1, 0, 100], [0, 1, 200]]) img_dst1 = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))

在这里插入图片描述

缩放

在这里插入图片描述

M = cv2.getRotationMatrix2D((img.shape[1]*0.5, img.shape[0]*0.5), 0, 0.5) img_dst = cv2.warpAffine(img, M, (width, height))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PRwO35Uy-1628429086477)(en-resource://database/2127:1)]

镜像

图像的镜像变换,包括水平镜像、垂直镜像和对角镜像。

水平镜像: 在这里插入图片描述

M = np.float32([[-1, 0, width], [0, 1, 0]]) img_dst = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4VqYb2T4-1628429086478)(en-resource://database/2129:1)]

垂直镜像: 在这里插入图片描述 M = np.float32([[1, 0, 0], [0, -1, height]]) img_dst = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yCrceqJJ-1628429086479)(en-resource://database/2131:1)]

对角镜像:

在这里插入图片描述

M = np.float32([[-1, 0, width], [0, -1, height]]) img_dst = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YVLLOaVi-1628429086480)(en-resource://database/2133:1)]

转置

在这里插入图片描述

M = np.float32([[0, 1, 0], [1, 0, 0]]) img_dst = cv2.warpAffine(img, M, (img.shape[0], img.shape[1]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eIcE36Dk-1628429086480)(en-resource://database/2135:1)]

错切(倾斜)

在这里插入图片描述

d   x   = t a n ( θ ) d~x~ =tan(θ) d x =tan(θ), d   y   = 0 d~y~ =0 d y =0 沿着X方向错切

d   x   = 0 d~x~ =0 d x =0, d   y   = t a n ( θ ) d~y~ =tan(θ) d y =tan(θ) 沿着Y方向错切

M = np.float32([[1, np.tan(0.1), 0], [0, 1, 0]]) img_dst = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oVPIXFTH-1628429086481)(en-resource://database/2137:1)]

刚体变换 2D 的旋转和平移变换/rotation,translation, 3个自由度点与点之间的距离不变,保角性

x , = ( R ⃗ T ⃗ ) x x^,= \left(\begin{matrix} \vec{R} & \vec{T} \end{matrix}\right)x x,=(R ​T ​)x

相似变换 相似变换包括旋转、平移变换,增加了均匀的缩放,4个自由度点之间的距离变化,但是比例保持不变,保角性。

x , = ( s R T 0 ⃗ 1 ) x x^,=\left(\begin{matrix} sR & T \\ \vec{0} & 1 \end{matrix}\right)x x,=(sR0 ​T1​)x

仿射变换 仿射变换包括旋转(两个方向)、平移变换、缩放变换(两个尺度)、倾斜(错切)变换、翻转变换,6个自由度,没有保持保角性和点距比值,但是具有保持平行性。保持平直性和平行性,但是角度会变二维坐标到二维坐标之间的线性变换 在这里插入图片描述 src_point = np.float32([[526, 233],[1010, 411],[499, 1217]]) dst_point = np.float32([[92, 408],[628, 252],[972, 1058]]) warp_mat = cv2.getAffineTransform(src_point, dst_point) img1_warp = cv2.warpAffine(img1, warp_mat, (img1.shape[1], img1.shape[0]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KbJHK3Lv-1628429086482)(en-resource://database/2139:1)]

投影变换 透视变换,单应变换8个自由度,四组对应点求解保持直线性,但是不保持平行性二维到三维的映射

在这里插入图片描述

src_point = np.array([[526, 233],[1010, 411],[499, 1217],[53, 861]]) dst_point = np.array([[92, 408],[628, 252],[972, 1058],[303, 1300]]) H, _ = cv2.findHomography(src_point, dst_point) img1_warp = cv2.warpPerspective(img1, H, (img2.shape[1], img2.shape[0]))

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sENryQez-1628429086482)(en-resource://database/2141:1)]



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3