Analysis of DICOM files on the. NET platform

Source: Internet
Author: User

[Digress]

In fact, I have long wanted to re-write my blog, but there are always various reasons to "persuade" myself to be lazy. This internship in a small company, I want to parse DICOM files, and I think it is necessary to record something, this is also the first article of Benbo.Article.

 

[Article Index]

    1. Composition of DICOM files
    2. Open-source class library fo-DICOM on the. NET platform
    3. Several Problems in use
    4. Related Links

 

1. Composition of DICOM files]

I personally feel that, although there may be various class libraries to parse a file, it is still necessary to understand the structure of the Minimum File, in this way, the idea of using the class library will be clearer.

In general, the DICOM file format is still very clear. To put it simply, it can be divided into three parts:

    1. The first part is the introduction (preamble) of the DICOM file, which starts to fix 128 bytes. However, since this can be left empty, the first 128 bytes of all DICOM files are set to 0;
    2. The second part is the identification of the 4-byte file followed by "dicm". If not, it indicates that it is not a DICOM file;
    3. The third part is the dataset. The dataset contains several data elements. The dataset contains the file metadata (file meta data element), patient and health check data, private data element, and image, cover layer, and other data (encoding of pixel, overlay and waveform data ).

For each data element, it contains four parts as shown in:

    1. Data Element identification tag (two-byte uint16 group number and two-byte uint16 element number );
    2. Data presentation type value representation (2 single-byte char, in some cases, two bytes are reserved for 0, such as 0x20 0x00 0x01 0x00 );
    3. Data Length Value length (2 bytes uint16, in some cases 4 bytes uint32, such as 0x20 0x00 0x01 0x00 );
    4. Data content value field (Length: Value length. If VL = 0 xffffffff, you must always read the deadline ).

The storage and presentation formats of data content are associated with VR (see section 5, 24th of the standard). However, VR does not exist, that is, there may be implicit conditions (which need to be determined based on element identifiers), in addition, VR attributes may also be UN (unknown) and so on.Of course, you can understand this unless you want to write the parsing on your own.

 

(2) Open-source class library fo-DICOM on the. NET platform]

. NET platform in fact there are a lot of useful DICOM Parsing Library, there is a class library called mdcm (https://github.com/rcd/mdcm ), ability to read most DICOM files (there are several 16-digit films with deep color analysis deviations, there are still several test software films that cannot be read, and then 32-digit color films are not supported ), the author has also stopped updating the class library. But fortunately, after the fo-DICOM (https://github.com/rcd/fo-dicom), it feels the same as mdcm (CodeMany of them are the same), and the above problems have been solved. At least I can analyze the films from several hospitals.

To obtain the fo-DICOM, go to the GitHub link provided above to download the code. You can click the zip package on the toolbar above to download all the code and compile it locally. It should be noted that the project is Based on. NET 4.0. Because the project contains C ++ code, if you use vs2012 to open it, you need to update it to VC ++ 2012 for compilation. In fact, if JPEG resolution is not required, you only need to compile the DICOM project.

Fo-DICOM highly encapsulates the DICOM file format. First, a DICOM file is a dicomfile class (Using DICOM). You can create it from the file like this:

 
Dicomfile dcmfile = dicomfile. Open (filepath );

Or, you can create a file from a stream like this:

 
Dicomfile dcmfile = dicomfile. Open (Stream );

To obtain data elements in DICOM files, you must obtain them from DICOM data. Unlike mdcm, fo-DICOM provides a generic method, instead of providing a method for each type. In addition, like mdcm, fo-DICOM encapsulates all data element Identifiers (tags). You do not need to consider the number of tags, you only need to provide what you need. The dicomtag class provides thousands of encapsulated static classes to choose from. For example:

 
Dicomdataset dcmdataset =Dcmfile. dataset; string patientname= Dcmdataset. Get <string> (dicomtag. patientname );

To obtain image information, create a dicomimage class (Using DICOM. Imaging), for example:

Dicomimage dcmimage =NewDicomimage (dcmdataset );//You can add the second parameter to specify the number of frames to be retrieved.Image image = dcmimage. renderimage ();

Fo-DICOM is better than mdcm in that it also places windowcenter and wide wwidth in the dicomimage class, you can directly modify the two parameters in the dicomimage class to obtain and set the window slot and window width. After you adjust the renderimage, instead of adjusting the parameters in the dataset, re-create the dicomimage class (which not only simplifies the operation but also improves the submission efficiency). For example:

 
Dcmimage. windowcenter =300; Dcmimage. 1_wwidth=1500;

 

[3. Several Problems in use]

1. In a windowcenter and mongowwidthProgramThe system prompts that the array is out of bounds and the program crashes.

Modify DICOM/imaging/LUT/outputlut. the public int this [int value] (CS) Indexer shields comments from the four lines that have been commented out (judge the part of value <0 and> 255 ). I don't know why the author commented out the four lines because of the debugging program or other reasons. The same is true for the mdcm file. In actual testing, for some windowcenter and mongowwidth, in this place, the array may be out of bounds.

2. Adjust the painting color of the overlays layer.

Modify the constant overylaycolor in DICOM/imaging/dicomimage. CS;

3. output the rotated image directly when outputting the image.

Modify DICOM/imaging/dicomimage. in CS, the renderimage method is executed after the graphic object of imagegraphic is created. rotate (angle) method. If angle is greater than zero, it indicates the degree of rotation to the right. If it is less than zero, it indicates the degree to the left, therefore, you can create an attribute in dicomimage to set the Rotation Degree or directly input the Rotation Degree in the renderimage method.

 

[4. Related Links]

1. DICOM format file parser: http://www.cnblogs.com/assassinx/archive/2013/01/09/dicomViewer.html
2. DICOM standard Medical Image File Analysis and tool software development: http://wenku.baidu.com/view/7511df2c2af90242a895e524.html
3, The DICOM Standard: http://medical.nema.org/standard.html

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.