SimpleITK 的学习一

 

#SimpleITK在dcm图像的应用

import SimpleITK as sitk
import numpy as np

dcm_file = 'dir_path/test.dcm'

 

#获取图像的tag信息
image = sitk.ReadImage(dcm_file)

keys = image.GetMetaDataKeys()
for key in keys:
    print key, image.GetMetaData(key)

 

#更改tag信息
value = ''
image.SetMetaData(key, value)

 

#获取图像的大小
image_size = image.GetSize()

 

#获取图像数值
image_array = sitk.GetArrayFromImage(img)
np_array = np.int16(image_array) 

 

#文件夹中只包含一个series
file_dir = ''
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(file_dir)
reader.SetFileName(dicom_names)
image = reader.Execute()
sitk.WriteImage(image, image_path)

 

#文件夹中包含多个series
series_ids = reader.GetGDCMSeriesIDs(file_dir)
for series_id in series_ids:
    dicom_names = reader.GetGDCMSeriesFileNames(file_dir, series_id)
    reader.SetFileName(dicom_names)
    image = reader.Execute()
    sitk.WriteImage(image, image_path)

你可能感兴趣的:(SimpleITK 的学习一)