Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DICOM undefined tag length, PIXELs

Tags:

dicom

I'm writing some software to read DICOM files and I am not sure how to deal with tags that have an undefined length. The standard says that

"If the Value Field has an Explicit Length, then the Value Length Field shall contain a value equal to the length (in bytes) of the Value Field. Otherwise, the Value Field has an Undefined Length and a Sequence Delimitation Item marks the end of the Value Field. "

So to read a value with undefined length FFFFFFFF I would continue reading bytes until I hit a sequence delimitation item FFFEE0DD. What happens if the value contains a series of bytes that happen to be equal to a sequence delimitation item? How do I correctly locate the sequence delimitation item?

like image 671
Codey McCodeface Avatar asked Jan 02 '14 09:01

Codey McCodeface


1 Answers

Undefined attributes are used in DICOM for both SQ tags, and for Pixel Data (7fe0,0010). In both cases, The chunks of data can be encoded using one more more Item Tags (FFFE,E000), and the end of the attribute is signaled by the Sequence Delimitation Item (FFFE,E0DD).

In the case of Pixel Data, each fragment of pixel data is encoded with an Item Tag (FFFE,E000). Each fragment of pixel data is encoded as a fixed length. Each frame of the pixel data can be composed of one or more fragments of pixel data. The first Item Tag encoded in the pixel data is a basic offset table. If a frame is encoded with more than one fragment, this offset table will tell the offset within the pixel data of each frame. If the offset table is zero length, then each frame is encoded in single fragment. You can see an example of the encoding in DICOM Part 5, Table A.4-1. In any case, you should be able to parse the contents of the pixel data by repeatedly reading 8 bytes of pixel data to get the Item Tag/Sequence Delimiter Item + the length of each fragment, then reading the actual number of bytes specified by the length, and repeating.

You can see an example for SQ attribute encoding in Part 5 of DICOM, Table 7.5-2 and Table 7.5-3. This works in a similar fashion, with the exception that the length associated with an item tag could be "undefined length". In the case of Sequences, however, you can keep parsing the contents of the sequences, since they're just tag data anyways.

like image 70
Steve Wranovsky Avatar answered Sep 28 '22 22:09

Steve Wranovsky