Ahmed Farghaly
Ahmed Farghaly

Reputation: 1

SimpleITK WriteImage Error, DICOM does not support this component type

I am getting this error when running my program: RuntimeError: Exception thrown in SimpleITK ImageFileWriter_Execute: D:\a\1\sitk-build\ITK\Modules\IO\GDCM\src\itkGDCMImageIO.cxx:1392: ITK ERROR: GDCMImageIO(000002F885196800): DICOM does not support this component type The program is a simple DICOM 2D series reader that should then write the read series into a DICOM file (see below). I have the latest SimpleITK version.

directory = "I:\y"
output_file = r"I:\x.dcm"
print("Reading Dicom directory:", directory)
reader = sitk.ImageSeriesReader()

dicom_names = reader.GetGDCMSeriesFileNames(directory)
reader.SetFileNames(dicom_names)
image = reader.Execute()


size = image.GetSize()

print("Image size:", size[0], size[1], size[2])
if os.path.isfile(output_file):
    print("yes")
    sitk.WriteImage(image, output_file)
else:
    print("path not found")

I found some reports on this error, but the voxel values were floats. In my case the voxel values are int16.

Upvotes: 0

Views: 986

Answers (1)

Dave Chen
Dave Chen

Reputation: 2085

You're reading a 2d DICOM series into a 3d volume, and then trying to write the 3d volume out as a 3d DICOM. SimpleITK only supports writing 2d DICOM series. So you need to slice that 3d volume up into another 2d series of images, then write each image as an individual DICOM image.

The SimpleITK documentation has an example that shows how to do that: https://simpleitk.readthedocs.io/en/master/link_DicomSeriesReadModifyWrite_docs.html

Upvotes: 0

Related Questions