我目前正在执行一项任务,需要使用NumPy,Matplotlib(Marchingcubes,Triangulation或Volumemodel)将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);
答案 0 :(得分:0)
有一个加载一组2D CT切片并构建3D阵列的示例。
https://github.com/pydicom/pydicom/blob/master/examples/image_processing/reslice.py
它不会继续构建表面,但是应该可以解决问题的前半部分。