dicom学习笔记之二:数据元素编码
VM:value multiply =如果数据类型是字符串,就会用反斜杠把相关的值区分开来;如果是字节流,就需要用长度和当前的类型进行除法运算来获取。
在显式语法中,如果VR值是OB, OW, OF, SQ, UT, UN类型
Tag
VR
Value Length
Value
Group
Number
(16-bit
unsigned
integer)
Element
Number
(16-bit
unsigned
integer)
VR(2 byte character string) of
"OB",
"OW",
“OF”,
“SQ”, “UT”
or "UN"
Reserved
(2 bytes)
set to a
value of
0000H
32-bit unsigned
integer
Even number of bytes containing the Data Element Value(s) encoded according to the VR and negotiated Transfer Syntax. Delimited with
Sequence Delimitation Item if of Undefined
Length.
2 bytes
2 bytes
2 bytes
2 bytes
4 bytes
'Value Length' bytes if of Explicit Length
否则的话,
Tag
VR
Value Length
Value
Group
Number
(16-bit
unsigned
integer)
Element
Number
(16-bit
unsigned
integer)
VR
(2 byte character
string)
(16-bit unsigned
integer)
Even number of bytes containing the Data Element Value(s) encoded according to the VR and negotiated Transfer Syntax.
2 bytes
2 bytes
2 bytes
2 bytes
'Value Length' bytes
在隐式的情况下:
Tag
Value Length
Value
Group
Number
(16-bit
unsigned
integer)
Element
Number
(16-bit
unsigned
integer)
32-bit unsigned integer
Even number of bytes
containing the Data
Elements Value
encoded according to
the VR specified in PS
3.6 and the negotiated
Transfer Syntax.
Delimited with
Sequence Delimitation
Item if of Undefined
Length.
2 bytes
2 bytes
4 bytes
'Value Length' bytes or
Undefined Length
在dcmtk代码如下:
/* read the value in the length field. In some cases, it is 4 bytes wide, in other */ /* cases only 2 bytes (see DICOM standard (year 2000) part 5, section 7.1.1) (or the */ /* corresponding section in a later version of the standard) */ if (xferSyn.isImplicitVR() || nxtobj == EVR_na) //note that delimitation items don't have a VR { inStream.read(&valueLength, 4); //length field is 4 bytes wide swapIfNecessary(gLocalByteOrder, byteOrder, &valueLength, 4, 4); bytesRead += 4; } else { //the transfer syntax is explicit VR DcmVR vr(newTag.getEVR()); if (vr.usesExtendedLengthEncoding()) { Uint16 reserved; inStream.read(&reserved, 2); // 2 reserved bytes inStream.read(&valueLength, 4); // length field is 4 bytes wide swapIfNecessary(gLocalByteOrder, byteOrder, &valueLength, 4, 4); bytesRead += 6; } else { Uint16 tmpValueLength; inStream.read(&tmpValueLength, 2); // length field is 2 bytes wide swapIfNecessary(gLocalByteOrder, byteOrder, &tmpValueLength, 2, 2); bytesRead += 2; valueLength = tmpValueLength; } }