赞
踩
- import sys
- import os
- import numpy as np
- import SimpleITK as sitk
-
- def sitk_dcms_read2(dcm_dir):
- reader = sitk.ImageSeriesReader();
- seriesIDs = reader.GetGDCMSeriesIDs(dcm_dir)
- dcm_series = reader.GetGDCMSeriesFileNames(dcm_dir, seriesIDs[0])
- reader.SetFileNames(dcm_deries)
- itkimage =reader.Execute()
- numpyImage = sitk.GetArrayFromImage(itkimage)
- numpyOrigin = np.array(list(reversed(itkimage.GetOrigin())))
- numpySpacing = np.array(list(reversed(itkimage.GetSpacing())))
- return numpyImage ,numpyOrigin,numpySpacing
-
-
- def save_itk(image, origin, sapce, filename):
- if type(origin) != tuple:
- if type(origin) == list:
- origin = tuple(reversed(origin))
- else:
- origin = tuple(reversed(origin.tolist()))
- if type(spacing) != tuple:
- if type(spacing) == list:
- spacing = tuple(reversed(spacing))
- else:
- spacing = tuple(reversed(spacing.tolist()))
- itkimage = sitk.GetImageFromArray(image, isVector=False)
- itkimage.SetSpacing(spacing)
- itkimage.SetOrigin(origin)
- sitk.WriteImage(itkimage, filename, True)
-
-
- ###示例
- raw_path = "D://case01"
- filename = "D://case01.vtk"
- imgs, origin, spacing = sitk_dcms_red2(filename)
- save_itk(imgs, origin, spacing, filename)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。