Edit private tag with Pydicom

387 Views Asked by At

I am trying to edit a private tag from a RTPLAN with Pydicom

First, I read the dicom file : ds = dicom.read_file('dicomfile')

The tag I want to modify is enter image description here

I tried the command : ds[0x4001, 0x1012] = 'test'

but it returns the following error :

TypeError: Dataset items must be 'DataElement' instances

How could I modify the value of that tag ?

1

There are 1 best solutions below

1
darcymason On BEST ANSWER

The simple answer, since the private data element already exists in this case, is to simply change its value:

 ds[0x4001,0x1012].value = b'test'

Another answer is to look at the documentation on working with Private Data Elements where more flexible ways of working with them are described.