suyashkumar / dicom

⚡High Performance DICOM Medical Image Parser in Go.
MIT License
933 stars 136 forks source link

Value representation "Application Entity" is not correclly serialized #275

Closed bench closed 1 year ago

bench commented 1 year ago

Some DICOM files containing a VR of type AE are not properly serialized.

For example, the following dicom file is valid. It contains, among other things, the following header.

(0002, 0016) Source Application Entity Title AE: 'CLUNIE1'

By deserializing and serializing the file again, the field (0002, 0016) is modified and takes the value

(0002, 0016) Source Application Entity Title AE: 'CLUNIE1\x00'

According to the official specification, values with VRs constructed of character strings, except in the case of the VR UI, shall be padded with SPACE characters (20H, in the Default Character Repertoire) when necessary to achieve even length.

Also, the value is a string of characters that identifies an Application Entity with leading and trailing spaces (20H) being non-significant. A Value consisting solely of spaces shall not be used.

The binary part of the header defining "Application Entity Title" is detailed below.

image

What ? Meaning
02 group number
16 group number
4145 AE
0800 8 bytes length (must be an even number!)
434c 554e 4945 3120 C L U N I E 1 + SPACE

Once deserialized, the space character should be ignored because it is non-significant but here the space is replaced by a ZERO.

Refs

https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html https://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_7.html#table_7.1-2