图像平移 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



