tagsprivatedicompydicom

Edit private tag with Pydicom


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 ?


Solution

  • 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.