python 中的 DICOM 切片顺序
DICOM slicing orders in python
我对切片排序有疑问:
我有大约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 Class UID 是 CT 图像存储。
这是代码,这是结果图片。
slices = sorted(slices, key=lambda x: x.ImagePositionPatient[2])
可能是您想要的,具体取决于您的 SOP Class UID 是什么。
我对切片排序有疑问:
我有大约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 Class UID 是 CT 图像存储。
这是代码,这是结果图片。
slices = sorted(slices, key=lambda x: x.ImagePositionPatient[2])
可能是您想要的,具体取决于您的 SOP Class UID 是什么。