我使用 Matplotlib 在 python 中创建了一个可爱的 3D 位移矢量场,我对结果很满意。然而,从视觉上看不是很东,只能看到位移的大小方向。在 python 中有没有一种方法可以为箭头使用色标,以便位移的大小更清晰/更明显。
这是我到目前为止
#%% Import Libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
#%% Import tsv file of results
path = 'W:/Scott/Continuous_DIC_Results/A35_L7-8_500x500x1000/'
name = 'Z=-5,200,-20,20,spm100'
results = np.loadtxt(path+name+'.tsv', dtype=float, comments='#', delimiter=None, converters=None, skiprows=1, usecols=(1,2,3,4,5,6), unpack=False, ndmin=0)
Z,Y,X = results[:,0], results[:,1],results[:,2]
dz,dy,dx = results[:,3],results[:,4],results[:,5]
#%% Plot Displacement Field
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.quiver(X, Y, Z, dx, dy, dz, # data
length=20, # arrow length
color='Tomato' # arrow …Run Code Online (Sandbox Code Playgroud) 我创建了一个3D中值滤镜,它可以正常工作,并且如下所示:
def Median_Filter_3D(image,kernel):
window = np.zeros(shape=(kernel,kernel,kernel), dtype = np.uint8)
n = (kernel-1)/2 #Deals with Image border
imgout = np.empty_like(image)
w,h,l = image.shape()
Run Code Online (Sandbox Code Playgroud)
每个像素的%%启动循环
for y in np.arange(0,(w-n*2),1):
for x in np.arange(0,(h-n*2),1):
for z in np.arange(0,(l-n*2),1):
window[:,:,:] = image[x:x+kernel,y:y+kernel,z:z+kernel]
med = np.median(window)
imgout[x+n,y+n,z+n] = med
return(imgout)
Run Code Online (Sandbox Code Playgroud)
因此,在每个像素处,它都会创建一个大小为kernelxkernelxkernel的窗口,找到该窗口中像素的中值,然后用新的中值替换该像素的值。
我的问题是,它非常缓慢,我需要处理数千个大图像。必须有一种更快的方法来遍历所有这些像素,并且仍然能够获得相同的结果。
提前致谢!!