明霞山资源网 Design By www.htccd.com
如下所示:
import cv2 import math import numpy as np def move(img): height, width, channels = img.shape emptyImage2 = img.copy() x=20 y=20 for i in range(height): for j in range(width): if i>=x and j>=y: emptyImage2[i,j]=img[i-x][j-y] else: emptyImage2[i,j]=(0,0,0) return emptyImage2 img = cv2.imread("e:\\lena.bmp") cv2.namedWindow("Image") SaltImage=move(img) cv2.imshow("Image",img) cv2.imshow("ss",SaltImage) cv2.waitKey(0)
旋转:
import cv2 import math import numpy as np def XRotate(image, angle): h, w, channels = image.shape anglePi = angle * math.pi / 180.0 cosA = math.cos(anglePi) sinA = math.sin(anglePi) X1 = math.ceil(abs(0.5 * h * cosA + 0.5 * w * sinA)) X2 = math.ceil(abs(0.5 * h * cosA - 0.5 * w * sinA)) Y1 = math.ceil(abs(-0.5 * h * sinA + 0.5 * w * cosA)) Y2 = math.ceil(abs(-0.5 * h * sinA - 0.5 * w * cosA)) hh = int(2 * max(Y1, Y2)) ww = int(2 * max(X1, X2)) emptyImage2 = np.zeros((hh, ww, channels), np.uint8) for i in range(hh): for j in range(ww): x = cosA * i + sinA * j - 0.5 * ww * cosA - 0.5 * hh * sinA + 0.5 * w y = cosA * j- sinA * i+ 0.5 * ww * sinA - 0.5 * hh * cosA + 0.5 * h x = int(x) y = int(y) if x > -1 and x < h and y > -1 and y < w : emptyImage2[i, j] = image[x, y] return emptyImage2 image = cv2.imread("e:\\lena.bmp") iXRotate12 = XRotate(image, 30) cv2.imshow('image', image) cv2.imshow('iXRotate12', iXRotate12) cv2.waitKey(0)
以上这篇python 图像平移和旋转的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
python,图像,平移,旋转
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。