栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python图像几何变换

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python图像几何变换

图像的平移

图像平移 Translation 是将图 像中所有的点都按照指定的平移量,进行水平、垂直移动。

x self.trans.x
y self.trans.y
# img[x:h-1,y:w-1] image[0:h-1-x,0:w-1-y]
for j in range(h):
 for i in range(w):
 i0 i x
 j0 j y
 if(i0 0) and (i0 w) and (j0 0)and (j0 h):
 img[j0,i0] image[j,i]
图像镜像变换

图像的镜像变换分为两种 一种是水平镜像,另一种是垂直镜像。
图像的水平镜像操作是以原图像的垂直中轴线为中心 将图像分为左右两部分进行对称变换
图像的垂直镜像操作是以原图像的水平中轴线为中心 将图像分为上下两部分进行对称变换。
镜像变换后图的高和宽都不变。

水平镜像

垂直镜像

 for j in range(h):
 for i in range(w):
 img[j,i] image[j,w-1-i]
 XImage.imShow(img, self.lb_2)
 for j in range(h):
 for i in range(w):
 img[j, i] image[h-1-j,i]
 XImage.imShow(img, self.lb_2)
图像缩放


 image self.image.xBitmap.img_org
 h, w, c image.shape
 # 转置影响宽和高
 ax self.zoom.x
 ay self.zoom.y
 aH int(ay * h)
 aW int(ax * w)
 out np.zeros((aH, aW, c), dtype np.uint8)
 for y in range(aH):
 for x in range(aW):
 x0 int(x / ax)
 y0 int(y / ay)
 out[y, x] image[y0, x0]
 XImage.imShow(out, self.lb_2)
图像旋转

图像旋转必须指明图像绕着什么旋 转。一般图像的旋转是以图像的中心为原点 旋转一定的角度。 旋转后 一般会改变图像的大小。

理论链接:https://blog.csdn.net/imxlw00/article/details/118207971

# 绕中心的旋转
 def rotate(self,img, angle):
 H, W, C img.shape
 anglePi angle * math.pi / 180.0
 cosA math.cos(anglePi)
 sinA math.sin(anglePi)
 out np.zeros((H, W, C), dtype np.uint8) # 必须是8 不然显示不出图像
 for y in range(H):
 for x in range(W):
 x0 int(cosA * x - sinA * y - 0.5 * W * cosA 0.5 * H * sinA 0.5 * W)
 y0 int(sinA * x cosA * y - 0.5 * W * sinA - 0.5 * H * cosA 0.5 * H)
 if 0 x0 W and 0 y0 H: # 计算结果是这一范围内的x0 y0才是原始图像的坐标。
 out[y0, x0] img[y, x]
 return out
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267412.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号