我已经能够在python中使用lewiner marching cubes algorithm。它输出顶点,面和其他属性。我想确保它能正常工作,所以我想绘制一个函数返回的3D图像。但是,到目前为止,我还没有任何成功。我尝试了以下方法:
成功检索必填字段:
verts, faces, normals, values = skimage.measure.marching_cubes_lewiner(var,20,spacing=(0.5,0.5,0.5))
以及未成功获取的图:
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(projection='3d')
mesh = Poly3DCollection(verts[faces])
mesh.set_edgecolor('k')
ax.add_collection3d(mesh)
还有:
vv.mesh(np.fliplr(verts), faces, normals, values) # doctest: +SKIP
假设地,我想在机器学习算法中使用顶点,面等,但是我想确保返回的值是可靠的。任何人都有类似这样的经历吗?
我不知道您是否还在寻找答案,但是我也遇到了通过该功能绘制网格的问题。我没有任何错误,但情节空虚。如果您也是这种情况,我通过指定轴限制来解决。以下对我有用:
import matplotlib.pyplot as plt
import numpy as np
from skimage.measure import marching_cubes_lewiner
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
# mask is a currently stored binary 3D numpy array
verts, faces, normals, values = marching_cubes_lewiner(mask)
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection="3d")
ax.set_xlim(np.min(verts[:,0]), np.max(verts[:,0]))
ax.set_ylim(np.min(verts[:,1]), np.max(verts[:,1]))
ax.set_zlim(np.min(verts[:,2]), np.max(verts[:,2]))
mesh = Poly3DCollection(verts[faces])
mesh.set_edgecolor('k')
ax.add_collection3d(mesh)
plt.tight_layout()
plt.show()