【问题标题】:How to plot output from marching_cubes_lewiner in python?python - 如何在python中绘制marching_cubes_lewiner的输出?
【发布时间】:2020-02-20 16:33:53
【问题描述】:

我已经能够在 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

假设,我想在机器学习算法中使用顶点、面等,但我想确保返回的值是可靠的。有没有人有过这样的经历?

【问题讨论】:

    标签: python machine-learning 3d marching-cubes


    【解决方案1】:

    我不知道你是否还在寻找这个问题的答案,但我刚刚也遇到了通过这个函数绘制网格的问题。我没有得到任何错误,而是一个空的情节。如果您也是这种情况,我通过指定轴限制来解决它。以下对我有用:

    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()
    

    【讨论】:

    • 我很久以前就知道了,但感谢您的工作。设置坐标轴限制的方式尤其有用。
    猜你喜欢
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 2022-01-22
    相关资源
    最近更新 更多