使用 dicom2nifti 转换无法正常工作

Conversion not working properly using dicom2nifti

我为每位患者准备了一系列 dicom 文件 (.dcm),我想将其转换为 nii.gz 文件,但是以下转换没有任何反应(甚至是错误信息)...

import dicom2nifti
dicom2nifti.settings.set_gdcmconv_path('C:/Program Files/GDCM 3.0/bin/gdcmconv.exe')
dicom2nifti.convert_directory('M0_1', 'M0_1.nii.gz')

尝试其他方法时出现错误....

import dicom2nifti
dicom2nifti.settings.set_gdcmconv_path('C:/Program Files/GDCM 3.0/bin/gdcmconv.exe')
dicom2nifti.dicom_series_to_nifti('M0_1', 'M0_1.nii.gz')

错误日志:

Traceback (most recent call last):
  File ".\test.py", line 5, in <module>
    dicom2nifti.dicom_series_to_nifti('M0_1', 'M0_1.nii.gz')
  File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\convert_dicom.py", line 78, in dicom_series_to_nifti
    return dicom_array_to_nifti(dicom_input, output_file, reorient_nifti)
  File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\convert_dicom.py", line 112, in dicom_array_to_nifti
    if not are_imaging_dicoms(dicom_list):
  File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\convert_dicom.py", line 151, in are_imaging_dicoms
    if common.is_philips(dicom_input):
  File "D:\Anaconda3\envs\pydicom\lib\site-packages\dicom2nifti\common.py", line 102, in is_philips
    header = dicom_input[0]
IndexError: list index out of range

文件结构:

M0_1
   |----IM-0001-0001.dcm
   |----IM-0001-0002.dcm
   ........
   |----IM-0001-000299.dcm
   |----IM-0001-000300.dcm

环境: windows10, python: 3.6, dicom2nifti2.3.0

我哪里做错了?

或者有没有其他的转换方式?

提前致谢!

我没用过 dicom2nifti,但你可以使用 SimpleITK 将 DICOM 转换为 Nifti。

下面是应该完成这项工作的代码:

import SimpleITK as sitk

reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames('M0_1')
reader.SetFileNames(dicom_names)
image = reader.Execute()

# Added a call to PermuteAxes to change the axes of the data
image = sitk.PermuteAxes(image, [2, 1, 0])

sitk.WriteImage(image, 'M0_1.nii.gz')

您可以在此处了解有关 SimpleITK 的更多信息:https://simpleitk.readthedocs.io/

更新:我添加了对 SimpleITK 的 PermuteAxes 的调用以将轴顺序从 X-Y-Z 更改为 Z-Y-X。