Element VRs and Python typesΒΆ
DICOM elements can contain anything from ASCII strings to unicode text, decimals, floats, signed and unsigned integers of different byte-depth and even encoded data. The format of the value of an element is given by its Value Representation or VR, and a list of VRs is given in the DICOM Standard in Part 5, Table 6.2-1.
So when using pydicom, what Python type should be used with a given VR to ensure that the value gets written correctly?
Elements of any VR:
Can be set as empty by using
None
Can have their values set using their set using or stored as type from the table below
Non-SQ element values:
Can also be set using a
list
of their set using type - for Value Multiplicity (VM) > 1, the value will be stored as aMultiValue
of their stored as typeHowever, according to the DICOM Standard, elements with VR LT, OB, OD, OF, OL, OW, ST, UN, UR and UT should never have a VM greater than 1.
SQ element values should be set using a
list
of zero or moreDataset
instances.To ensure AT elements are encoded correctly, their values should be set using the 8-byte integer form of the tag - such as
0x00100020
for the tag (0010,0020) - and not as a 2-tuple or 2-list.
VR |
Name |
Set using |
Stored as |
---|---|---|---|
AE |
Application Entity |
||
AS |
Age String |
||
AT |
Attribute Tag |
||
CS |
Code String |
||
DA |
Date |
||
DS |
Decimal String |
||
DT |
Date Time |
||
FL |
Floating Point Single |
||
FD |
Floating Point Double |
||
IS |
Integer String |
||
LO |
Long String |
||
LT |
Long Text |
||
OB |
Other Byte |
||
OD |
Other Double |
||
OF |
Other Float |
||
OL |
Other Long |
||
OV |
Other 64-bit Very Long |
||
OW |
Other Word |
||
PN |
Person Name |
||
SH |
Short String |
||
SL |
Signed Long |
||
SQ |
Sequence of Items |
||
SS |
Signed Short |
||
ST |
Short Text |
||
SV |
Signed 64-bit Very Long |
||
TM |
Time |
||
UC |
Unlimited Characters |
||
UI |
Unique Identifier (UID) |
||
UL |
Unsigned Long |
||
UN |
Unknown |
||
UR |
URI/URL |
||
US |
Unsigned Short |
||
UT |
Unlimited Text |
||
UV |
Unsigned 64-bit Very Long |