DICOM在python中的切片顺序

问题描述 投票:0回答:1

我对切片排序有疑问:

我有大约80张髋关节照片,但没有从脚到头或从头到脚排列。

有没有办法按预定顺序排列它们?

# pixel aspects, assuming all slices are the same
ps = slices[0].PixelSpacing
ss = slices[0].SliceThickness


ax_aspect = ps[1]/ps[0]
sag_aspect = ps[1]/ss
cor_aspect = ss/ps[0]

# create 3D array
img_shape = list(slices[0].pixel_array.shape)
img_shape.append(len(ct_images))
print(img_shape)

img3d = np.zeros(img_shape)

# fill 3D array with the images from the files
for i, s in enumerate(slices):
    img2d = s.pixel_array
    img3d[:, :, i] = img2d

# plot 3 orthogonal slices
a1 = plt.subplot(2,2,1)
plt.imshow(img3d[:,:,img_shape[2]//2])
a1.set_aspect(ax_aspect)

a2 = plt.subplot(2,2,3)
plt.imshow(img3d[:,img_shape[1]//2,:])
a2.set_aspect(sag_aspect)

a3 = plt.subplot(2,2,2)
plt.imshow(img3d[img_shape[0]//2,:,:].T)
a3.set_aspect(cor_aspect)


plt.show()

SOP类UID是CT图像存储。

这是代码,这是结果的图片。

All pictures of transverse view

3D view

python matplotlib slice dicom pydicom
1个回答
0
投票

slices = sorted(slices, key=lambda x: x.ImagePositionPatient[2])可能是您想要的,这取决于您的SOP类UID是什么。

© www.soinside.com 2019 - 2024. All rights reserved.