首先,构建表单的旋转矩阵
[cos(theta) -sin(theta) 0]
R = [sin(theta) cos(theta) 0]
[0 0 1]
应用此坐标变换可以围绕原点进行旋转.
相反,如果要围绕图像中心旋转,则必须先移动图像中心
到原点,然后应用旋转,然后将所有东西都移回去.你可以用一个
翻译矩阵:
[1 0 -image_width/2]
T = [0 1 -image_height/2]
[0 0 1]
然后,用于平移,旋转和反向平移的变换矩阵变为:
H = inv(T) * R * T
我将不得不考虑如何将偏斜矩阵与3D变换联系起来.我希望最简单的方法是设置一个4D变换矩阵,然后将其投影回2D齐次坐标.但就目前而言,偏斜矩阵的一般形式如下:
[x_scale 0 0]
S = [0 y_scale 0]
[x_skew y_skew 1]
x_skew和y_skew值通常很小(1e-3或更小).
这是代码:
from skimage import data, transform
import numpy as np
import matplotlib.pyplot as plt
img = data.camera()
theta = np.deg2rad(10)
tx = 0
ty = 0
S, C = np.sin(theta), np.cos(theta)
# Rotation matrix, angle theta, translation tx, ty
H = np.array([[C, -S, tx],
[S,