\begin{bmatrix}u \\v\end{bmatrix}=\begin{bmatrix} \cos\theta & \sin\theta \\-\sin \theta &\cos\theta \end{bmatrix} \times \left \{ \begin{bmatrix}k _{x} -1 &\gamma _{x } \\\gamma _{y } &k _{y} -1\end{bmatrix}\times \begin{bmatrix} x\\y\end{bmatrix} +{\textstyle \sum_{j=1}^{N}\begin{bmatrix}A_{y}^{j} e^{\frac{-1}{2} \left ( \frac{y-y_{1}^{j} }{\sigma _{y_{1} }^{j} } \right )^2-\frac{1}{2} \left (\frac{x-x_{1}^{j} }{\sigma _{x_{1} }^{j} } \right ) ^2 } \\A_{x}^{j} e^{\frac{-1}{2} \left ( \frac{x-x_{0}^{j} }{\sigma _{x_{0} }^{j} } \right )^2-\frac{1}{2} \left (\frac{y-y_{0}^{j} }{\sigma _{y_{0} }^{j} } \right ) ^2 }\end{bmatrix}} \right \} +\begin{bmatrix}t_{x} \\t_{y}\end{bmatrix},N=1or2 X=y=256,tx,ty 范围:-4.0到4.0像素,有效最大位移:2.0像素;kx,ky 范围:0.96到1.04,有效最大位移:5.1;theta 范围:-0.01至0.01rad , 有效最大位移: 2.4像素;gammax,gammay 范围:-0.03至0.03,有效最大位移: 3.8像素;Ax,Ay范围:0.003到0.6 ;sigmaх0,sigmay0,sigmax1,sigmay1范围:0.06到0.5,x0,y0,x1,y1范围:0到511,最终生成一个可视化的应边场图片(w.r.t最终图像大小:128x128 )
时间: 2023-07-17 12:04:25 浏览: 108
根据您提供的方程和参数范围,以下是一个更新后的代码示例,用于生成可视化的应边场图片:
```python
import numpy as np
import matplotlib.pyplot as plt
# 参数设置
N = np.random.choice([1, 2]) # 随机选择N的值为1或2
X = y = 256 # 图像大小为256x256像素
tx_min, tx_max = -4.0, 4.0
ty_min, ty_max = -4.0, 4.0
kx_min, kx_max = 0.96, 1.04
ky_min, ky_max = 0.96, 1.04
theta_min, theta_max = -0.01, 0.01
gammax_min, gammax_max = -0.03, 0.03
gammay_min, gammay_max = -0.03, 0.03
Ax_min, Ax_max = 0.003, 0.6
Ay_min, Ay_max = 0.003, 0.6
sigmax0_min, sigmax0_max = 0.06, 0.5
sigmay0_min, sigmay0_max = 0.06, 0.5
sigmax1_min, sigmax1_max = 0.06, 0.5
sigmay1_min, sigmay1_max = 0.06, 0.5
x0_min, x0_max = 0, 511
y0_min, y0_max = 0, 511
x1_min, x1_max = 0, 511
y1_min, y1_max = 0, 511
# 随机生成参数值
tx = np.random.uniform(tx_min, tx_max)
ty = np.random.uniform(ty_min, ty_max)
kx = np.random.uniform(kx_min, kx_max)
ky = np.random.uniform(ky_min, ky_max)
theta = np.random.uniform(theta_min, theta_max)
gammax = np.random.uniform(gammax_min, gammax_max)
gammay = np.random.uniform(gammay_min, gammay_max)
Ax = np.random.uniform(Ax_min, Ax_max)
Ay = np.random.uniform(Ay_min, Ay_max)
sigmax0 = np.random.uniform(sigmax0_min, sigmax0_max)
sigmay0 = np.random.uniform(sigmay0_min, sigmay0_max)
sigmax1 = np.random.uniform(sigmax1_min, sigmax1_max)
sigmay1 = np.random.uniform(sigmay1_min, sigmay1_max)
x0 = np.random.randint(x0_min, x0_max+1)
y0 = np.random.randint(y0_min, y0_max+1)
x1 = np.random.randint(x1_min, x1_max+1)
y1 = np.random.randint(y1_min, y1_max+1)
# 生成网格坐标
x_grid, y_grid = np.meshgrid(range(X), range(y))
# 计算数学方程
A = np.array([[kx-1, gammay], [gammax, ky-1]])
B = np.stack((x_grid, y_grid), axis=-1).reshape(-1, 2).T
C = np.array([[Ay * np.exp(-0.5 * ((y_grid-y1)/sigmay1)**2 - 0.5 * ((x_grid-x1)/sigmax1)**2)],
[Ax * np.exp(-0.5 * ((x_grid-x0)/sigmax0)**2 - 0.5 * ((y_grid-y0)/sigmay0)**2)]])
D = np.dot(A, np.dot(B, C)) + np.array([[tx], [ty]])
u = D[0].reshape(X, y)
v = D[1].reshape(X, y)
# 绘制图像
fig, ax = plt.subplots(figsize=(5, 5))
plt.quiver(x_grid, y_grid, u, v)
ax.set_xlim(0, X-1)
ax.set_ylim(0, y-1)
plt.grid(True)
plt.show()
```
这段代码使用了`np.meshgrid`函数生成网格坐标,并计算出每个坐标点对应的u和v值。然后使用`plt.quiver`函数绘制出应边场图片。最终生成的图片大小为128x128像素,范围在0到255之间。你可以根据需要自行调整参数范围和图像大小。
阅读全文