我現在只能轉180度:
import numpy as np
import math
import matplotlib.pyplot as plt
def my_flip(img1, type):
nr, nc = img1.shape[:2]
u = np.zeros( [ nr, nc ], dtype = 'uint8' )
A =np.mat([[math.cos(math.pi),-math.sin(math.pi)], [math.sin(math.pi), math.cos(math.pi)]])
#A =np.mat([[math.cos(math.pi),-math.sin(math.pi)], [math.sin(math.pi), math.cos(math.pi)]])
for r in range(nr):
for l in range(nc):
v = np.dot(A.I, np.array([r, l]).T)
u[r, l] = img1[int(v[0, 0]), int(v[0, 1])]
return u
我不想用包,我想用python寫數學公式
uj5u.com熱心網友回復:
圍繞 (0,0) 旋轉 90 度由簡單的公式描述:
newx = -oldy
newy = oldx
您可以將這些轉換應用于 np 陣列,而無需使用一般型別的旋轉矩陣。
旋轉 180 度也是
newx = -oldx
newy = -oldy
陣列求反看起來比矩陣形成和其他行為更簡單,不是嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/518224.html
標籤:Python数学图像旋转
