icometrix / dicom2nifti

MIT License
339 stars 79 forks source link

Converting using dicom2nifti didn't work #109

Closed Minxiangliu closed 2 years ago

Minxiangliu commented 2 years ago

I have a series of dicom files (.dcm) for each patient that I want to convert to nii.gz files, but nothing happens (even error info) with the following conversion...

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')

The error occurs when trying other methods....

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')

Error Log:

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

File structure:

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

Environment: windows10, python: 3.6, dicom2nifti2.3.0

Where am I doing wrong? Thanks in advance!

blakedewey commented 2 years ago

This looks like your DICOM files aren't being recognized as "valid" by dicom2nifti. Can you run the following code from the same directory? This should help isolate what is going on.

from dicom2nifti.compressed_dicom import read_file, is_dicom_file
from dicom2nifti.common import is_valid_imaging_dicom
if is_dicom_file('M0_1/IM-0001-0001.dcm'):
    print('DICOM file!')
    dicom_headers = read_file('M0_1/IM-0001-0001.dcm')
    if is_valid_imaging_dicom(dicom_headers):
        print('Valid DICOM!')
    else:
        print('Invalid DICOM!')
else:
    print('Not DICOM file')