URGENT: pydicom 'UN'/'Unknown' tag

Skip to first unread message

Student Saver

Sep 5, 2020, 10:19:01 AM9/5/20
to pydicom

I'm trying to read the value of my NumberOfSlicesMR tag I get the following value: UN: b'h\x01\x00\x00'. I'm not sure how to interpret this but I did come across. this statement online: UN: Unknown: A string of bytes where the encoding of the contents is unknown (see Section 6.2.2 of Digital Imaging and Communications in Medicine (DICOM) - Part 5: Data Structures and Encoding).

I'd appreciate any help as this is for a project I need to complete ASAP! 


Darcy Mason

Sep 5, 2020, 12:45:31 PM9/5/20
to pydicom
As the documentation says, UN is used for unknown encoding - all DICOM information is encoded in bytes, but then converted by pydicom to strings, floats, etc. according to the type.  In this case, the type is unknown, so pydicom leaves it as bytes.

You will have to figure out what the correct encoding is with some known information.  In this case, since it is a count of slices, it is most likely an integer.  For example, assuming you have little-endian order and a long integer:

   import struct
   bytes_string = b'h\0x01\x00\x00'
   struct.unpack('<L', bytes_string)[0]

gives 360, which seems a reasonable value as number of slices.

There are ways you could automate this somewhat.  For example, if you had multiple UN to deal with, you could look into the documentation for `data_element_callback` to write some code which could check and deal with various UN elements.

Hope that helps
Reply all
Reply to author
0 new messages