How to get RawData from Private Tag Data

1,279 views
Skip to first unread message

kingaza

unread,
Jan 15, 2014, 9:20:21 PM1/15/14
to pyd...@googlegroups.com
Hello,

I am really new to pydicom, but i love it at once.
Now I am trying to access raw data in a dicom file by reading a private tag data, i.e. (0x7fe1, 0x1010). So how can I do?

Thx a lot~~
Kingaza

Darcy Mason

unread,
Jan 15, 2014, 11:01:46 PM1/15/14
to pyd...@googlegroups.com

On Wednesday, January 15, 2014 9:20:21 PM UTC-5, kingaza wrote:
Hello,

I am really new to pydicom, but i love it at once.
Now I am trying to access raw data in a dicom file by reading a private tag data, i.e. (0x7fe1, 0x1010). So how can I do?


Hi kingaza,

You can get at the raw bytes just using the tag and value property, like this example using the test file CT_small:

>>> ds=dicom.read_file("CT_small.dcm")
>>> arr = ds[0x431028].value
>>> arr[:6]
'CT01\x00\x00'

where 'arr' will then be a normal python string of bytes, so as in the last line, you can slice it, iterate over it, etc.

But... pydicom will pick up the VR if it is an unambiguous entry in the private dictionary (it also did in example above, it just happened to be OB type, which is also what you get if pydicom doesn't know the VR). If the VR is known, you can use it like normal pydicom data elements:

>>> ds[0x431031]
(0043, 1031) [Recon Center Coordinates]          DS: ['-11.200000', '9.700000']
>>> ds[0x431031].value
['-11.200000', '9.700000']

It looks like the (0x7fe1, 0x1010) you mentioned is a possible tag from multiple vendors. If you know which one, and can find out what VR the item is, then you can update the pydicom dictionary to add that information (there have been several threads about updating the dictionary that should be easy to find). Then you would be able to use the value without working with raw bytes.

Darcy

kingaza

unread,
Jan 16, 2014, 12:35:00 AM1/16/14
to pyd...@googlegroups.com
Hi Darcy,

Thx for the quick reply.
I try by following your hint, and it works.
Then I type the data set infomation, and found the VR of the private tag is OW, in little endian. that is why I can get a large string. And I still try to convert it to an encoded string... Do you have any suggestion?

And then, the next step is to add this tag into the dictionary.

Best Regards,
kingaza


在 2014年1月16日星期四UTC+8下午12时01分46秒,Darcy Mason写道:

Darcy Mason

unread,
Jan 16, 2014, 7:26:11 AM1/16/14
to pyd...@googlegroups.com


On Thursday, January 16, 2014 12:35:00 AM UTC-5, kingaza wrote:
Hi Darcy,

Thx for the quick reply.
I try by following your hint, and it works.
Then I type the data set infomation, and found the VR of the private tag is OW, in little endian. that is why I can get a large string. And I still try to convert it to an encoded string... Do you have any suggestion?


Pydicom still returns the OW as if it were an OB, so you just have a string of bytes. Probably what you want to do is to use python's struct module unpack() function to convert them to a tuple of values.
 
Darcy
Reply all
Reply to author
Forward
0 new messages