Python 如何将 2D DICOM 切片转换为 3D 图像

How to convert 2D DICOM slices to 3D image in Python

我目前正在执行一项任务,我需要使用 NumPy、Matplotlib、(Marchingcubes、三角测量或体积模型)将 DICOM 切片绘制到一个 3D 模型中

我试过这个网站的方法:

https://www.raddq.com/dicom-processing-segmentation-visualization-in-python/

但不幸的是我没有成功

import pydicom
import numpy as np 
import os
import matplotlib.pyplot as plt
import ipywidgets as widgets
from ipywidgets import interact, fixed


filesNew = []
datenSatz = []


output_path = './Head/'
print()

def load_scan(path):
    slices = [pydicom.read_file(path + '/' + s) for s in os.listdir(path)]
    slices.sort(key = lambda x: int(x.InstanceNumber))
    try:
        slice_thickness = np.abs(slices[0].ImagePositionPatient[2] - slices[1].ImagePositionPatient[2])
    except:
        slice_thickness = np.abs(slices[0].SliceLocation - slices[1].SliceLocation)

    for s in slices:
        s.SliceThickness = slice_thickness

    return slices

for s in load_scan('./Head/'):
    h = s.pixel_array
    datenSatz.append(s) #dataSet from the patient
    filesNew.append(h) #pixel_array





def show_image(image_stack, sliceNumber):
    pxl_ar = image_stack[sliceNumber]
    #print(np.array_equal(pxl_ar,filesNew[sliceNumber]))
    plt.imshow(pxl_ar, cmap= plt.cm.gray)
    plt.show()


slider = widgets.IntSlider(min=0,max=len(filesNew)-1,step=1,value = 0, continuous_update=False)
interact(show_image, image_stack = fixed(filesNew), sliceNumber = slider);

DICOM slices visualized

有一个加载一组2D CT切片并构建3D阵列的示例。

https://github.com/pydicom/pydicom/blob/master/examples/image_processing/reslice.py

它不会继续构建表面,但它应该解决你问题的前半部分。