可变形图像配准位移矢量场可视化

import numpy as np
import matplotlib.pyplot as plt
import cv2
def plot_grid(ax, gridx,gridy, **kwargs):
    for i in range(gridx.shape[0]):
        ax.plot(gridx[i,:], gridy[i,:], **kwargs)
    for i in range(gridx.shape[1]):
        ax.plot(gridx[:,i], gridy[:,i], **kwargs)

rand_field_norm=np.load("C:/Users/lenovo/Desktop/show/1/911_mfdxdy.npy")#读取变形场即为dxdy
print(np.max(rand_field_norm))
print(np.min(rand_field_norm))#注意你所生成的变形场的单位!!!
fig, ax = plt.subplots()

grid_x,grid_y = np.meshgrid(np.linspace(-1,1,72),np.linspace(-1,1,72))#生产网格大小

plot_grid(ax,grid_x,grid_y, color="lightgrey")
distx=grid_x+rand_field_norm[0::4,0::4,0] #间隔取变形场
disty=grid_y+rand_field_norm[0::4,0::4,1]
# distx=np.clip(distx,-1,1)
# disty=np.clip(disty,-1,1)
plot_grid(ax,distx, disty, color="C0")
plt.xticks([])  #去掉横坐标值
plt.yticks([])  #去掉纵坐标值
plt.show()
plt.savefig()#保存图像

你可能感兴趣的:(可变形图像配准位移矢量场可视化)