我想绘制DICOM扫描的3D可视化效果,但我陷在这个错误中。
我正在使用行进多维数据集方法。首先从网格顶点和面返回,然后返回到plt_3d。导入的模块:
将numpy导入为np
将pydicom导入为pyd
导入操作系统
将matplotlib.pyplot导入为plt
从glob导入glob
从mpl_toolkits.mplot3d.art3d导入Poly3DCollection
导入scipy.ndimage
从skimage导入形态学
来自skimage导入度量
从skimage.transform导入调整大小
从sklearn.cluster导入KMeans
从密谋导入版本
从plotly.offline导入download_plotlyjs,init_notebook_mode,plot,iplot
从plotly.tools中将FigureFactory导入为FF
从plotly.graph_objs导入*
init_notebook_mode(connected = True)
imgs_after_resamp是包含DICOM数据的像素阵列(3d)
def make_mesh(image,threshold=-300,step_size=1):
p = image.transpose(2,1,0)
verts,faces,norm,val = measure.marching_cubes_lewiner(p,threshold,step_size=step_size,allow_degenerate=True)
print(verts)
return verts,faces
def plotly_3d(verts,faces):
x,y,z = zip(*verts)
fig = FF.create_trisurf(x=x,y=y,z=z,plot_edges=False,colormap=colormap,simplices=faces,backgroundcolor='rgb(64,64,64)',title="Interactive Visualization")
iplot(fig)
def plt_3d(verts,faces):
print(“Drawing”)
x,z = zip(*verts)
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111,projection='3d')
mesh = Poly3DCollection(verts[faces],linewidths=0.05,alpha=1)
face_color = [1,0.9]
mesh.set_facecolor(face_color)
ax.add_collection3d(mesh)
ax.set_xlim(0,max(x))
ax.set_ylim(0,max(y))
ax.set_zlim(0,max(z))
ax.set_axis_bgcolor((0.7,0.7,0.7))
plt.show()
v,f = make_mesh(imgs_after_resamp,350)
new3d=np.vectorize(plt_3d)
new3d(v,f)
ValueError跟踪(最近一次通话最近) 在 ----> 1个plot_ve(imgs_re,400)
TypeError:*之后的类型对象参数必须是可迭代的,而不是numpy.float32