DICOM and dicomdir

Source: Internet
Author: User

The DICOM file content is defined in Part 3 dicom iod. CT, Mr, Cr, Dr, US, nm, pet, XA and so on have their own content definitions, composed of a common proprietary part (ie and modules.
Dicomdir is defined by Part 10. Is a mini variable-length database file structure.

 

In the past, I was handed down to a computer-wise Indian who asked me: isn't the image file format BMP, GIF, Tif, and JPEG? Why do we need to define DICOM? I explained to him several times that I finally gave up. The format of any image file is composed of two parts: the header of the parameter and the pixel data ). BMP, JPEG, Tiff, and other format headers only describe the basic parameters of the image, such as several lines, strong lines, a few bits for each vertex, whether the image is compressed, and the color palette. Headers are usually fixed in length. Medical Imaging also requires many other parameters, such as basic patient data, basic exam data, series data, and location data. In addition, each modality is different from the content required by each image. Therefore, the general image format cannot be used.
Four levels of DICOM content:
1. Patient (patient)
2. Study (test)
3. Series)
4. Image)
Although the content of the first few layers is the same in many images, they must be included in each image file. Each layer is called an Information Entity or IE (referenced from the relational database schema design ). Each layer is subdivided into modules. The smallest unit in each module is an attribute or element.

Here is an example:
CR image
DICOM part 3, a.2.3, table A.2-1
1. Patient ie: A. Patient module (refer to c.7.1.1)
2. Study ie: A. Study Module (see c.7.2.1) B. Patient Study Module (see c.7.2.2)
3. Series ie: A. General series (see c.7.3.1) B. Cr series (see c.8.1. 1) C. General equipment (see c.7.5.1)
4. Image ie: A. genrral image (c.7.6.1) B. image pixel (c.7.6.3) C. Contrast/bolus (c.7.6.4) D. CR image (c.8.1.2)
...
I. SOP common (C.12.1)
Find all elements in these modules (tables) and create a CR image architecture. Note that some of these modules are mandatory (modatory) and some are selected by users ). In each module, the attribute/element table contains five types: Type 1, 1C, 2, 2c, and 3. Type 1 is required, and 2 is required, but the content can be empty. Type 3 is optional. Therefore, there are not many elements in a CR image.

 

After the tables are expanded, these elements form a dataset. What is the format for writing to a file or transmitting it over the network? This depends on Part 5.
The structure of an element is:
1. Group Tag: 16-bit
2. Element Tag: 16-bit
3. Length (or VR/length): 32-bit
4. Data (bytes of length)
Each element DICOM Standard Part 6 that is used defines a group tag and an element tag.
For example: Patient Name: 0x0010, 0x0010 patient id: 0x0010, 0x0020...
VR refers to the element format. For example, the VR of patinet name Is PN. The format is last_name ^ first_name ^ middle_name ^ prefix ^ surfix. My English name is: Wang ^ JB ^ dr. ^
When writing data out, you need to do the following:
1. Sort all elements by group tage and element tag (SORT ). From small to large.
2. If the DICOM file is written into DICOM media, first write 128 bytes preamble (usually blank), add "dicm", and add group 2 meta header. (Let's Talk About Part 10)
3. If the dataset contains sequence elements, each item in the sequence is a dataset.

 

Job: with this knowledge, you can start to write a small Conversion Program from BMP to DICOM.
Key materials:
Modality (0008,006 0): SC
Photometric interpretation (4, 0028,000): RGB
Sop class uid: 1.2.840.10008.1.5.4.1.1.7
The simplest way is to write a structure and then

array. typedef struct DicomElem(short int group_tag, short int element_tag, char VR[4], int length, char data[128]) DicomElem; DicomElem CRDataSet [] = ( ( 0x0008, 0x0005, "CS", 10, "ISO_IR 100"), ( 0x0008, 0x0008, "CS", 16, "ORIGINAL\\PRIMARY"), ... (0x0010, 0x0010, "PN", 16, "My^Test^Image^^ "), (0x0010, 0x0020, "SH", 6, "123456"), ... (0,0,"",0,"") ); void WriteCDImage(FILE *fp){DicomElem elem = CRDataSet[0]; unsigned long int lComboTag; int nCols, nRows; unsigned char *pPixelData unsigned long int lPixelLength; pPixelData = LoadBMPImgeData("MyImage.bmp", nCols, nRows, lPixelLength); while(CRDataSet.group_tag){ lComboTag = (CRDataSet.group_tag << 16) | CRDataSet.element_tag;switch(lComboTag) {case 0x00280010: *((short int *)CRDataSet.data) = nCols; break; case 0x00280011: *((short int *)CRDataSet.data) = nRows; break; ... } // Write group and element tag fwrite(&lComboTag, 1, sizeof(long), fp); // Write VR fwrite(CRDataSet.VR, 1, 2, fp); if (lComboTag != 0x7fe00010) { fwrite(CRDataSet.length, 1, sizeof(short), fp); fwrite(CRDataSet.data, 1, CRDataSet.length, fp); }else{fwrite("\0\0", 1, 2, fp); // Two blank bytes after VR fwrite(&lPixelLength, 1, sizeof(long), fp); // Length fwrite(pPixelData, 1, lPixelLength, fp);}i++; }}unsigned char *LoadBMPImgeData(char *fileName, int &nCols, int &nRows, unsigned long &lPixelLength) ( .... )

  

Write the details by yourself.

 

Next floor: the hardest thing to read and write DICOM files is:
O dicom Sequence
O dicom pixel data
There is no sequence in the job we just made, and pixel data is also very simple. The analogy of sequence in C is a structure array. It is a structure set structure. So it is difficult to read. What's more annoying is that sequence can also not define the length, that is, the length is-1. You need to find (fffe, e0dd) to determine whether the sequence ends. Each structure unit in array is an item in DICOM sequence. An item starts with a specific element (fffe, e000 ). If the length of an item is-1, the end of the item is determined by finding (fffe, e00d. Pixel data (7fe0, 0010) is a special DICOM element. Always at the end of all elements. Its sequence has two similarities: The O length zone is always 32-bit (that is, in the case of explicit VR, you need to fill in two bytes behind the VR area, and then add the length of 4-bytes. O is compressed, and each graph is saved with an item. The first item is an offset table. The offset of each graph is a DWORD (4 bytes), and the offset of the first graph is 0.

DICOM media and dicomdir:
When DICOM images are transmitted through store SCU/SCP, the smallest group is (0008, xxxx). Generally, the first element is (0008,000 0) or (0008,000 5 ). There are two sets of things on the media (such as the disc, hard disk, and mod:
1. Preamble and DICOM Signature: 128 bytes (usually empty) followed by dicm.
2. Meta header: a dozen elements of group (0002, xxxx). See DICOM Part 10. Dicomdir is a variable-length mini database file. It is subject to group (0002, xxxx) and group (0004, xxxx. It describes a 4-layer tree structure ). 1. Patient 2. Study
3. Series 4. In addition to the common DICOM sequene, the image uses offset as the linked list. Therefore, reading and writing is troublesome. See DICOM Part 10.

DICOM Chinese support: DICOM itself can support any text. Applications may not be deciphered. DICOM images can be implemented using the following methods in Chinese: (,) Set "gb2312" or "big5 ". All texts are in double-byte GB or Big 5 yards. Most DICOM controls may be used incorrectly. The standard uses 8-bit bytes instead of 7-bit printable ASCII. For ANSI string functions such as sprintf, sscanf removes the highest bit. It must be rewritten to support wide character.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.