2

I am adding some private tags with VR "LO" to an already existing DICOM file. With something like:

dcm.add_new("70d12000", "LO", "Private tag content")

Getting the following output when printing the DICOM object:

(70d1, 2000) Private tag data LO: 'Private tag content'

However, when I write the DICOM file and try to load it again it is loaded with "UN" VR.

(70d1, 2000) Private tag data UN: Array of 20 elements

This only happens in some cases. Do you know how to fix this error to be able to load them again as LO?

  • What transfer syntax are you using to write the files? And what do you mean by "some cases" - does this happen for some tags in the same file, or for some files? – MrBean Bremen Mar 21 '22 at 19:26
  • 1
    If the transfer syntax is not *Explicit VR Little Endian* then the VR will be lost. If a private tag is included in pydicom's private data dictionary then it can be inferred on reading even when not explicitly defined. – scaramallion Mar 21 '22 at 22:12

1 Answers1

0

I had the same problem adding new tags and fixed it by changing the Transfer Syntax (as recommended in the comments) using this code. I put a code snippet just in case someone might find it usefull in the future.

import pydicom
ds = dcmread(implicit_vr_dataset)
ds.is_implicit_VR = False
ds.file_meta.TransferSyntaxUID = '1.2.840.10008.1.2.1'
ds.save_as('test.dcm', write_like_original=False)

In case the vaue doesn't correspond with the VR (for example trying to write '1.0' instead of '1' as a IS), it will be exported as UN.