ImagingDataCommons / libdicom

C library for reading DICOM files
https://libdicom.readthedocs.io
MIT License
15 stars 7 forks source link

Parsing errors of valid DICOM files #48

Closed CGDogan closed 1 year ago

CGDogan commented 1 year ago

I was able to find 3 DICOM files that fail with this library. Is it possible for you to investigate this? Many thanks dcm_files.zip

I didn't record where I took them from, except for 6.dcm from www.chameleon-software.de

jcupitt commented 1 year ago

Hi @CGDogan,

Thank you very much for testing this. There's a v0.2 of libdicom here that's not yet been merged to this repo:

https://github.com/jcupitt/libdicom

I see:

1.dcm

$ dcm-dump 1.dcm 
===File Meta Information===
(0002,0002) MediaStorageSOPClassUID | UI | 28 | 1.2.840.10008.5.1.4.1.1.12.1
(0002,0003) MediaStorageSOPInstanceUID | UI | 46 | 1.3.12.2.1107.5.4.3.321890.19960124.162922.29
(0002,0010) TransferSyntaxUID | UI | 22 | 1.2.840.10008.1.2.4.50
(0002,0012) ImplementationClassUID | UI | 8 | 999.999
ERROR    [Wed Mar 29 22:51:55 2023] - Parse error: Reading of Data Element header failed - Unknown or mismatched VR LO

3.dcm

$ dcm-dump 3.dcm 
===File Meta Information===
(0002,0003) MediaStorageSOPInstanceUID | UI | 64 | 1.2.826.0.1.3680043.8.1055.1.20111103112244831.30826609.78057758
(0002,0010) TransferSyntaxUID | UI | 18 | 1.2.840.10008.1.2
(0002,0012) ImplementationClassUID | UI | 28 | 1.2.826.0.1.3680043.8.1055.1
(0002,0013) ImplementationVersionName | SH | 16 | dicomlibrary-100
(0002,0016) SourceApplicationEntityTitle | AE | 12 | DICOMLIBRARY
CRITICAL [Wed Mar 29 22:52:29 2023] - DcmError set twice
ERROR    [Wed Mar 29 22:52:29 2023] - Parse error: Reading of Data Element header failed - Tag 00080000 not allowed in implicit mode

6.dcm

$ dcm-dump 6.dcm 
===File Meta Information===
(0002,0002) MediaStorageSOPClassUID | UI | 28 | 1.2.840.10008.5.1.4.1.1.3.1
(0002,0003) MediaStorageSOPInstanceUID | UI | 46 | 1.2.840.113863.1.2838173948.1.6985564519.34831
(0002,0010) TransferSyntaxUID | UI | 22 | 1.2.840.10008.1.2.4.50
(0002,0012) ImplementationClassUID | UI | 20 | 1.2.840.113680.21.1
(0002,0013) ImplementationVersionName | SH | 14 | DS21.1_S_6_07
ERROR    [Wed Mar 29 22:53:13 2023] - Parse error: Reading of Data Element header failed - Unknown or mismatched VR UL

I'll investigate these failures tomorrow.

jcupitt commented 1 year ago

Commit https://github.com/jcupitt/libdicom/commit/ce788f673038708273a8f0a894bc47f733a4f082 fixes cases 1 and 6.

Case 3 still fails, I'll check that next.

hackermd commented 1 year ago

I validated the files using the dciodvfy tool, and they have several standard conformity issues.

Specifically, case 3 violates basic DICOM encoding rules:

Warning - Missing attribute or value that would be needed to build DICOMDIR - Study Date
Warning - Missing attribute or value that would be needed to build DICOMDIR - Study Time
Warning - Missing attribute or value that would be needed to build DICOMDIR - Study ID
Warning - Missing attribute or value that would be needed to build DICOMDIR - Series Number
Warning - Value dubious for this VR - (0x0010,0x0010) PN Patient's Name  PN [1] = <Anonymized> - Retired Person Name form
Error - Value invalid for this VR - (0x0010,0x0020) LO Patient ID  LO - Trailing character invalid for this VR = '' (0)
Error - Dicom dataset contains invalid data values for Value Representations
Warning - Retired attribute - (0x0008,0x0000) UL Group Length
Warning - Retired attribute - (0x0010,0x0000) UL Group Length
Warning - Retired attribute - (0x0020,0x0000) UL Group Length
Warning - Retired attribute - (0x0028,0x0000) UL Group Length
Warning - Retired attribute - (0x7fe0,0x0000) UL Group Length
Warning - Dicom dataset contains retired attributes
SCImage
Error - Missing attribute Type 1 Required Element=<FileMetaInformationVersion> Module=<FileMetaInformation>
Error - Missing attribute Type 2 Required Element=<PatientBirthDate> Module=<Patient>
Error - Missing attribute Type 2 Required Element=<PatientSex> Module=<Patient>
Error - Missing attribute Type 2 Required Element=<StudyDate> Module=<GeneralStudy>
Error - Missing attribute Type 2 Required Element=<StudyTime> Module=<GeneralStudy>
Error - Missing attribute Type 2 Required Element=<ReferringPhysicianName> Module=<GeneralStudy>
Error - Missing attribute Type 2 Required Element=<StudyID> Module=<GeneralStudy>
Error - Missing attribute Type 2 Required Element=<AccessionNumber> Module=<GeneralStudy>
Error - Missing attribute Type 2 Required Element=<SeriesNumber> Module=<GeneralSeries>
Error - Missing attribute Type 2C Conditional Element=<Laterality> Module=<GeneralSeries>
Error - Missing attribute Type 2C Conditional Element=<PatientOrientation> Module=<GeneralImage>

The validator states that the "dataset contains invalid data values for Value Representations". We shouldn't expect libdicom to be able to parse the object.

CGDogan commented 1 year ago

Thanks! Case resolved