医疗图像三维重建方法小结(python+VTK+ITK+Mayavi)

这篇博客介绍了使用Python进行医疗图像三维重建的方法,包括Poly3DCollection+matplotlib的轻量化展示,VTK+ITK自建轮子的前处理与重建,以及Mayavi的contour3d和TVTK结合的解决方案。文章指出,虽然matplotlib显示简单但效果有限,而Mayavi+TVTK提供了更好的交互式三维显示,适合快速实现需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境简介

语言是python,主要介绍可能用到的库

  • Scipy
  • ITK
  • VTK
  • Mayavi
  • TVTK
  • Matplotlib

方法

在尝试重建三维模型的过程中,查询了不同版本的方法,在这里记录一下。

方法一 Poly3DCollection+matplotlib

使用mpl_toolkits 的Poly3DCollection,其中使用的是marching_cubes算法。
使用matplotlib进行显示。

import numpy as np
import pandas as pd
import os
import scipy.ndimage
import matplotlib.pyplot as plt
from skimage import measure, morphology
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

def plot_3d(image, threshold=-300):
    
    # Position the scan upright, 
    # so the head of the patient would be at the top facing the camera
    p = image.transpose(2,1,0)
    p = p[:,:,::-1]
    
    verts, faces = measure.marching_cubes(p, threshold)

    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], alpha=0.1)
    face_color = [0.5, 0.5, 1]
    mesh.set_facecolor(face_color)
    ax.add_collection3d(mesh)

    ax.set_xlabel("x-axis")
    ax.set_ylabel("y-axis")
    ax.set_zlabel("z-axis")

    ax.set_xlim(0, p.shape[0])  # a = 6 (times two for 2nd ellipsoid)
    ax.set_ylim(0, p.shape[1])  # b = 10
    ax.set_zlim(0, p.shape[2])  # c = 16

    plt.show()

优点:轻量化可以嵌入ipython里
缺点:

  • 不能旋转视图观察,可以使用poltly进行交互式显示。
  • 显示效果差,smooth的效果差。可以自己造轮子对源数据进行插值。然而插值始终不是基于Isosurface的,所以显示效果不会太好。

方法二 VTK+ITK

自己造轮子,基于VTK进行重建显示。

import vtk


def main():
    colors = vtk.vtkNamedColors()

    fileName = get_program_parameters()

    colors.SetColor("SkinColor", [255, 125, 64, 255])
    colors.SetColor("BkgColor", [51, 77, 102, 255])

    # Create the renderer, the render window, and the interactor. The renderer
    # draws into the render window, the interactor enables mouse- and
    # keyboard-based interaction with the data within the render window.
    #
    aRenderer = vtk.vtkRenderer()
    renWin = vtk.vtkRen
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值