其实SimpleITK文档里都有,直接搬过来
import SimpleITK as sitk
dicom_folder = "./MRA_219/"
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(dicom_folder)
reader.SetFileNames(dicom_names)
image = reader.Execute()
size = image.GetSize()
print("Image size:", size[0], size[1], size[2])
saveNiiPath = "./TOF_3D_multi-slab.nii.gz"
sitk.WriteImage(image,saveNiiPath,useCompression=True)
参考:
小插曲
参考:Read Image Meta-Data Dictionary and Print
reader = sitk.ImageFileReader()
reader.SetFileName(sys.argv[1])
reader.LoadPrivateTagsOn()
reader.ReadImageInformation()
for k in reader.GetMetaDataKeys():
v = reader.GetMetaData(k)
print(f'({k}) = = "{v}"')
print(f"Image Size: {reader.GetSize()}")
print(f"Image PixelType: {sitk.GetPixelIDValueAsString(reader.GetPixelID())}")