> I have some difficulties in reading the message length tag in some Dicom
> files. When I read the tags, the group and the element attributes are fine ,
> but when I read the 32 bits message length element, the first two bytes are
> corresponding to the VR, thus leading to a wrong message length.
> Is there a way to recognize this kind of files ? Does it have to be parsed
> from the dictionary ? What if the tag is not in the dictionary ?
You can tell if the data set is going to be Implicit VR or Explicit VR
by looking at the meta file header. The data element (0002,0010)
contains the transfer syntax used for the subsequent data set. I'm
guessing that you don't have DICOM part 10 standard files though, since
these have explicit VR in the header, and you would have had troubles
with them already. If the file is not a DICOM standard file with a
header, then you have to start parsing the file, and see if you
can figure out what the transfer syntax is from what you find there.
In the case of an Explicit VR data set, then the value length is not
always 32 bits as you suggest. For most elements you will have 2 bytes
for the VR and 2 bytes for the value length, but for OB, OW, and SQ
elements there is 2 bytes for the VR, 2 reserved bytes and then the
32 bit value length. See DICOM part 5, section 7 for details.
You do not have to use the data dictionary to parse a file stored in
Explicit VR - on the contrary - you need a data dictionary to parse
files stored with Implicit VR so that you can figure out what the
representation of the element is to decode it.
If a tag is not in your data dictionary, and the data set is encoded
in an Implicit VR transfer syntax, you might still be able to
parse the file. For data elements that you don't recognize, the
value length usually gives you enough information to skip over that
element and continue. If you come across a data element that is not
in your dictionary, and the value length is undefined (FFFFFFFFH)
then you're up the proverbial creek. This situation is not hopeless,
but it is too complicated to get into here.
Computer Vision Centre http://www.cvc.uab.es
Building O +34-93 581 27 80 (voice)
Autonomous University of Barcelona +34-93 581 16 70 (fax)
08193 Bellaterra (Barcelona), Spain +34-93 674 65 67 (home)