当前位置: 首页 > news >正文

网站仿制教程凡科建站网站

网站仿制教程,凡科建站网站,h5制作方法和步骤,株洲网站搜索优化旋转变换原理 旋转是仿射变换的一种,通过变换矩阵实现图像绕指定中心旋转,保持直线和平行性不变。其数学表示为: 其中: ( c x , c y ) (c_x, c_y) (cx​,cy​) 是旋转中心。 θ \theta θ 是旋转角度(逆时针为正&…

旋转变换原理

旋转是仿射变换的一种,通过变换矩阵实现图像绕指定中心旋转,保持直线和平行性不变。其数学表示为:
在这里插入图片描述
其中:

  • ( c x , c y ) (c_x, c_y) (cx,cy) 是旋转中心。
  • θ \theta θ 是旋转角度(逆时针为正)。

旋转矩阵的平移项用于补偿旋转中心的偏移。推导过程如下:

  1. 将旋转中心移到原点
    在这里插入图片描述

  2. 旋转
    [
\begin{bmatrix}
\cos\theta & -\sin\theta & 0 \
\sin\theta & \cos\theta & 0 \
0 & 0 & 1
\end{bmatrix}
]

  3. 移回原位置
    [
\begin{bmatrix}
1 & 0 & c_x \
0 & 1 & c_y \
0 & 0 & 1
\end{bmatrix}
]

  4. 合并后的矩阵(取前两行):
    [
M =
\begin{bmatrix}
\cos\theta & -\sin\theta & (1-\cos\theta)c_x + \sin\theta c_y \
\sin\theta & \cos\theta & -\sin\theta c_x + (1-\cos\theta)c_y
\end{bmatrix}
]

import numpy as np
import cv2
import matplotlib.pyplot as pltdef get_rotation_matrix(angle, center=None, scale=1.0):"""生成正确的2x3旋转仿射矩阵参数:angle: 旋转角度(度数,逆时针为正)center: (cx, cy)旋转中心坐标scale: 缩放比例返回:2x3仿射变换矩阵"""angle_rad = np.deg2rad(angle)cos = np.cos(angle_rad) * scalesin = np.sin(angle_rad) * scaleif center is None:raise ValueError("必须指定旋转中心")cx, cy = center# 计算平移分量tx = cx * (1 - cos) + cy * sinty = cy * (1 - cos) - cx * sinreturn np.array([[cos, -sin, tx],[sin,  cos, ty]])def warp_affine(image, M, dsize):"""手动实现仿射变换(支持多通道图像)参数:image: 输入图像(H,W,C)M: 2x3仿射变换矩阵dsize: 输出图像大小(width, height)返回:变换后的图像"""h, w = dsize[1], dsize[0]output = np.zeros((h, w, image.shape[2]), dtype=image.dtype)# 构造逆变换矩阵M_inv = np.vstack([M, [0, 0, 1]])M_inv = np.linalg.inv(M_inv)[:2]# 生成目标图像网格坐标y, x = np.indices((h, w))coords = np.stack([x, y, np.ones_like(x)], axis=-1)  # (H,W,3)# 计算原图坐标src_coords = np.dot(coords, M_inv.T)  # (H,W,2)# 双线性插值x_src = src_coords[:, :, 0]y_src = src_coords[:, :, 1]# 计算四个邻近点坐标x0 = np.floor(x_src).astype(int)y0 = np.floor(y_src).astype(int)x1 = x0 + 1y1 = y0 + 1# 处理边界x0 = np.clip(x0, 0, image.shape[1]-1)y0 = np.clip(y0, 0, image.shape[0]-1)x1 = np.clip(x1, 0, image.shape[1]-1)y1 = np.clip(y1, 0, image.shape[0]-1)# 计算权重wa = (x1 - x_src) * (y1 - y_src)wb = (x_src - x0) * (y1 - y_src)wc = (x1 - x_src) * (y_src - y0)wd = (x_src - x0) * (y_src - y0)# 对每个通道进行插值for c in range(image.shape[2]):output[:, :, c] = (wa * image[y0, x0, c] + wb * image[y0, x1, c] + wc * image[y1, x0, c] + wd * image[y1, x1, c])return output.astype(np.uint8)# 测试代码
if __name__ == "__main__":# 读取图像img = cv2.imread('example.jpg')img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)# 设置旋转参数angle = 45  # 旋转45度h, w = img.shape[:2]center = (w//2, h//2)  # 图像中心# 生成旋转矩阵M = get_rotation_matrix(angle, center)# 手动实现变换rotated_manual = warp_affine(img, M, (w, h))# 使用OpenCV实现对比rotated_cv = cv2.warpAffine(img, M, (w, h))# 显示结果plt.figure(figsize=(12, 6))plt.subplot(131), plt.imshow(img), plt.title('Original')plt.subplot(132), plt.imshow(rotated_manual), plt.title('Manual Rotation')plt.subplot(133), plt.imshow(rotated_cv), plt.title('OpenCV Rotation')plt.show()
http://www.cadmedia.cn/news/937.html

相关文章:

  • 东菀高端网站建设百度关键词快排
  • 大专有什么专业可以选百度快照优化排名怎么做
  • 营销网站建设工作seo百度首页排名业务
  • 中文网站建设翻译成英文是什么意思重庆seo薪酬水平
  • 辽宁建设工程信息网公司评分山东seo百度推广
  • 搜索网站有哪些安装百度到手机桌面
  • 日照网站建设哪家好seo咨询茂名
  • 搞笑视频素材网站免费石家庄谷歌seo公司
  • 建设工程月评打分网站站长工具seo优化
  • 邯郸建设局网站资质申报贺州seo
  • asp开发网站详细步骤网站优化推广seo公司
  • 未来中森网站建设公司sem优化公司
  • 给我一个网站图片营销网站类型
  • 网站建设过程中什么最重要百度引擎入口官网
  • 培训班管理系统 免费企业整站优化
  • 郑州政府网站建设如何做好网络营销管理
  • 安庆网站建设公司北京网站优化效果
  • 奉贤网站建设哪家好淘宝搜索关键词查询工具
  • wordpress汽车模版成都seo培
  • 大良网站建设收费外贸seo推广公司
  • 建立网站要钱吗网络推广渠道和方法
  • 楚雄市住房和城乡建设局网站网页设计框架
  • 外贸网站建设注意软文模板300字
  • 织梦和wordpress苏州seo营销
  • 峨边网站建设如何推广一个产品
  • 怎么才能找到想做网站建设的客源江苏seo技术教程
  • 药品网站网络营销推广怎么做网站链接分析工具
  • 资源网站建设怎么免费注册域名
  • 深圳住房和建设局网站 招标百度今日数据统计
  • 嘉兴电子商务网站建设如何查询网站收录情况