本笔记来源于B站Up主: 有Li 的影像组学的系列教学视频
本节(27)主要讲解: 功能强大的图像处理工具SimpleITK
包
视频中李博士演示了SimpleITK的两个基本功能:图像格式转换以及图像镜像翻转
- 导入SimipleITK包
import SimpleITK as sitk
- 从
.dcm
格式转换为.nii
格式
folderPath = 'C:/Users/RONG/Desktop/SimpleITK/'
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(folderPath)
reader.SetFileNames(dicom_names)
image = reader.Execute()
sitk.WriteImage(image, folderPath + 'test.nii.gz')
3.镜像翻转
image_arr = sitk.GetArrayFromImage(image) # Note: order:z, y, x !!
size = image.GetSize()
origin = image.GetOrigin() #order: x, y, z
spacing = image.GetSpacing() #order:x, y, z
direction = image.GetDirection()
print(spacing)
pixelType = sitk.sitkUInt8
image_new = sitk.Image(size,pixelType)
image_arr_new = image_arr[:,:,::-1]
image_new = sitk.GetImageFromArray(image_arr_new)
image_new.SetDirection(direction)
image_new.SetSpacing(spacing)
image_new.SetOrigin(origin)
sitk.WriteImage(image_new,folderPath + "test_reverseX.nii.gz")
SimpleITK包图像处理功能很强大,更多内容请探索其官网SIMPLEITK: A simplified path to Insight