当前位置:   article > 正文

SimpleITK Dicom序列数据读取_simpleitk读序列

simpleitk读序列
  1. import sys
  2. import os
  3. import numpy as np
  4. import SimpleITK as sitk
  5. def sitk_dcms_read2(dcm_dir):
  6. reader = sitk.ImageSeriesReader();
  7. seriesIDs = reader.GetGDCMSeriesIDs(dcm_dir)
  8. dcm_series = reader.GetGDCMSeriesFileNames(dcm_dir, seriesIDs[0])
  9. reader.SetFileNames(dcm_deries)
  10. itkimage =reader.Execute()
  11. numpyImage = sitk.GetArrayFromImage(itkimage)
  12. numpyOrigin = np.array(list(reversed(itkimage.GetOrigin())))
  13. numpySpacing = np.array(list(reversed(itkimage.GetSpacing())))
  14. return numpyImage ,numpyOrigin,numpySpacing
  15. def save_itk(image, origin, sapce, filename):
  16. if type(origin) != tuple:
  17. if type(origin) == list:
  18. origin = tuple(reversed(origin))
  19. else:
  20. origin = tuple(reversed(origin.tolist()))
  21. if type(spacing) != tuple:
  22. if type(spacing) == list:
  23. spacing = tuple(reversed(spacing))
  24. else:
  25. spacing = tuple(reversed(spacing.tolist()))
  26. itkimage = sitk.GetImageFromArray(image, isVector=False)
  27. itkimage.SetSpacing(spacing)
  28. itkimage.SetOrigin(origin)
  29. sitk.WriteImage(itkimage, filename, True)
  30. ###示例
  31. raw_path = "D://case01"
  32. filename = "D://case01.vtk"
  33. imgs, origin, spacing = sitk_dcms_red2(filename)
  34. save_itk(imgs, origin, spacing, filename)


参考:​​​​​​Python中利用SimpleITK读取DICOM文件 - 简书

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/165526?site
推荐阅读
相关标签
  

闽ICP备14008679号