代码之家  ›  专栏  ›  技术社区  ›  StuckInPhDNoMore

如何在三维图像上绘制坐标并显示它

  •  0
  • StuckInPhDNoMore  · 技术社区  · 7 年前

    我有一个三维图像作为一个分层的tif文件,它是一个二进制卷显示在特定位置的斑点。我还有一个预测算法的输出,该算法预测图像中所述斑点的坐标。

    imageio.volread imageio.volwrite 但是我想看看预测算法有多精确,所以我想把坐标标到图像上。坐标是 [x,y,z] 行数等于blob数的值。

    https://www.raddq.com/dicom-processing-segmentation-visualization-in-python/ ,我所做的尝试是利用 skimage.measure.marching_cubes matplotlib 然后用它来描绘我的形象。

    def make_mesh(image):
        print('Transposing surface')
        p = image.transpose(2, 1, 0)
    
        print('Calculating surface')
        verts, faces, norm, val = measure.marching_cubes_lewiner(p, allow_degenerate=True)
        return verts, faces
    
    def plt_3d(verts, faces):
        print('Drawing')
        x, y, z = zip(*verts)
        fig = plt.figure(figsize=(10, 10))
        ax = fig.add_subplot(111, projection='3d')
    
        # Fancy indexing: `verts[faces]` to generate a collection of triangles
        mesh = Poly3DCollection(verts[faces], linewidths=0.05, alpha=1)
        face_color = [1, 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()
    
    img_gt = io.volread(gt_path)
    v, f = make_mesh(img_gt)
    plt_3d(v, f)
    

    图像是一个 [21,512,1024] plot_3d 生成以下内容:

    enter image description here

    我不是在用电脑吗 marching_cubes 功能正常吗?为什么情节如此扭曲?原来的水滴是干净的球体,完全没有拉伸。

    此外,如果这是绘制我的图像的唯一方法,我将如何绘制我的图像 上面的坐标?

    0 回复  |  直到 7 年前