Import DICOM after format change from NETCDF using pydicom

OS: Windows 10 64bit
Slicer Version:4.10.0

Hi

I have a lab CT scan of an item stored in NETCDF (*.nc) format in multiple blocks. I would like to open this in Slicer. I have converted to dicom slices (1 file per slice) using the pydicom package in Python.

I understand that I have included all the required metadata. The dicom files can be successfully opened as a stack in a 2D program (ImageJ). The metadata is able to be queried in ImageJ.

When importing into Slicer, either by the DICOM import directory, or adding data using individual files, or even using the Patch DICOM function, errors were returned and the volume would not load.

From the error messages, it appears to be some problem in the meta data. One of the functions reports that the required field “PatientName” is not present, however it is present as is evident from the ImageJ metadata query.

Thanks for any assistance you can provide to debug this and allow this volume to be imported.

Below are the error messages and metadata from the import function, patch dicom and ImageJ.

-------- Import DICOM --------------
W: DcmMetaInfo: No Group Length available in Meta Information Header
W: DcmItem: Non-standard VR ’ ’ (08\00) encountered while parsing element (0008,0020), assuming 2 byte length field
W: DcmItem: Non-standard VR ‘06’ (30\36) encountered while parsing element (3032,3132), assuming 2 byte length field
W: DcmItem: Non-standard VR ’ ’ (00\00) encountered while parsing element (0000,0000), assuming 2 byte length field
W: DcmItem: Dataset not in ascending tag order, at element (0000,0000)
W: DcmItem: Non-standard VR ’ ’ (00\00) encountered while parsing element (0000,0000), assuming 2 byte length field
W: DcmItem: Element (0000,0000) found twice in one data set or item, ignoring second entry
W: DcmItem: Non-standard VR ’ ’ (00\00) encountered while parsing element (0000,0000), assuming 2 byte length field
W: DcmItem: Element (0000,0000) found twice in one data set or item, ignoring second entry
W: DcmItem: Non-standard VR ’ ’ (00\00) encountered while parsing element (0000,0000), assuming 2 byte length field
W: DcmItem: Element (0000,0000) found twice in one data set or item, ignoring second entry
W: DcmItem: Non-standard VR ’ ’ (00\00) encountered while parsing element (0000,0000), assuming 2 byte length field
W: DcmItem: Element (0000,0000) found twice in one data set or item, ignoring second entry

Could not load “<path_to_>/tomo00004.dcm”
DCMTK says: I/O suspension or premature end of stream

-------- Patch DICOM --------------
Traceback (most recent call last):
File “C:/Data/Utilities/Slicer 4.10.0/bin/…/lib/Slicer-4.10/qt-scripted-modules/DICOMPatcher.py”, line 154, in onPatchButton
self.logic.patchDicomDir(self.inputDirSelector.currentPath, self.outputDirSelector.currentPath)
File “C:/Data/Utilities/Slicer 4.10.0/bin/…/lib/Slicer-4.10/qt-scripted-modules/DICOMPatcher.py”, line 563, in patchDicomDir
rule.processDataSet(ds)
File “C:/Data/Utilities/Slicer 4.10.0/bin/…/lib/Slicer-4.10/qt-scripted-modules/DICOMPatcher.py”, line 223, in processDataSet
if ds.PatientName == ‘’:
File “C:\Data\Utilities\Slicer 4.10.0\lib\Python\Lib\site-packages\dicom\dataset.py”, line 256, in getattr
“’{0:s}’.”.format(name))
AttributeError: Dataset does not have attribute ‘PatientName’.

-------- ImageJ MetaData -----------
0002,0002 Media Storage SOP Class UID: 1.2.840.10008.5.1.4.1.1.2
0002,0003 Media Storage SOP Inst UID: 1.2.3
0002,0010 Transfer Syntax UID: 1.2.840.10008.1.2.1
0002,0012 Implementation Class UID: 1.2.3.4
0008,0020 Study Date: 20210609
0008,0030 Study Time: 110000.000000
0008,0050 Accession Number: 19078400556130
0008,0090 Referring Physician’s Name:
0010,0010 Patient’s Name: Something
0010,0020 Patient ID: 556130
0010,0030 Patient’s Birth Date: 19870113
0010,0040 Patient’s Sex: M
0018,0050 Slice Thickness: 0.01874854601919651
0020,0010 Study ID: 19078400556130
0020,0011 Series Number: 1
0020,0020 Patient Orientation:
0020,0032 Image Position (Patient): 0\0\0.07499418407678604
0020,1041 Slice Location: 0.07499418407678604
0028,0002 Samples per Pixel: 1
0028,0004 Photometric Interpretation: MONOCHROME2
0028,0010 Rows: 2520
0028,0011 Columns: 2520
0028,0030 Pixel Spacing: 0.018748546\0.018748546
0028,0100 Bits Allocated: 16
0028,0103 Pixel Representation: 0
7FE0,0010 Pixel Data: 600

(Fiji Is Just) ImageJ 2.1.0/1.53c; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 403MB of 48953MB (<1%)

Title: tomo00004.dcm
Width: 47.2463 mm (2520)
Height: 47.2463 mm (2520)
Size: 12MB
Resolution: 53.3375 pixels per mm
Pixel size: 0.0187x0.0187 mm^2
ID: -49
Bits per pixel: 16 (unsigned)
Display range: 0 - 21181
No threshold
Magnification: 0.33
ScaleToFit: false
Uncalibrated
Path: <path_to_>\tomo00004.dcm
Screen location: 152,52 (1920x1080)
No properties
No overlay
No selection

Creating valid DICOM files is very difficult. You would need to invest at least several days into learning about the DICOM standard and specific details about the information object that you want to create.

Instead of going into all this trouble, I would recommend to convert your data set into nrrd. For example, convert the volume to a numpy array and then save it using pynrrd.

1 Like

Thank you Andras.

I have experience with DICOM but it has been quite a while, so rusty and will take the time that you mention to get across everything.

Thank you for the recommendation of using pynrrd to save a numpy array. That did the trick and I have the volume saved and successfully imported into Slicer now.

While the original question is still open - that will require some research and playing around on my part, your suggestion provided the desired outcome much more simply and quickly. Thank you.

Task complete.

1 Like