Creating a new tag

376 views
Skip to first unread message

miki725

unread,
Jul 16, 2012, 1:07:16 PM7/16/12
to pyd...@googlegroups.com
Hi.

Usually I have no issues adding a new tag to a dicom. I just set the value in the dataset and if it a standard tag, then pydicom figures out the actual tag and everything works great. For example:

>>> ds = dicom.read_file('foo.dcm')
>>> ds.ImagesInAcquisition = 20
>>> ds.save_as('foo2.dcm')

However now I am working on a project where I need to export a standard tag Largest Image Pixel Value (0028,0107), however my usual method fails:

>>> ds = dicom.read_file('foo.dcm')
>>> ds.LargestImagePixelValue = 4095 # or ds[0x0028,0x0107].value = 4095
>>> ds.save_as('foo2.dcm')
ValueError: Cannot write ambiguous VR of 'US or SS' for data element with tag (0028, 0107).
Set the correct VR before writing, or use an implicit VR transfer syntax

I am pretty new to dicom and have no idea what this means. Can someone please explain what is going on and how can I fix it.

Thanx in advance.

Jonathan Suever

unread,
Jul 16, 2012, 1:24:24 PM7/16/12
to pyd...@googlegroups.com
What's going on here is that the dicom_dict entry for LargestImagePixelValue uses an ambiguous VR (Value Representation). It can either be an unsigned short integer (US) or a signed short integer (SS). In order to properly write the data to the file, you have to explicitly tell it which one you want to use. 

As the exception states, you need to either manually specify what VR you want to use, or write the file using implicit VR (essentially lets the program figure out which one to use). You most likely want to keep explicit VR and just set the VR for this element.

To do this try the following:

>>> ds = dicom.read_file('foo.dcm')
>>> ds.LargestImagePixelValue = 4095 # or ds[0x0028,0x0107].value = 4095
>>> ds[0x0028,0x0107].VR = 'US'
>>> ds.save_as('foo2.dcm')

Hope that helps.

-Jonathan



--
You received this message because you are subscribed to the Google Groups "pydicom" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pydicom/-/WYbjQWxc3hwJ.
To post to this group, send email to pyd...@googlegroups.com.
To unsubscribe from this group, send email to pydicom+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pydicom?hl=en.

miki725

unread,
Jul 16, 2012, 2:35:47 PM7/16/12
to pyd...@googlegroups.com
Thanx. It works now.
Reply all
Reply to author
Forward
0 new messages