DICOM Medical Image processing: "Multiple JPG image data stored in DCM files" by Dicom storage operations

Source: Internet
Author: User
Tags bmp image

background:

In this article, we continue to describe how to store multiple JPG image data in DCM files. The lossy compressed data is written directly to the DCM file and stored in multi-frame form.

multiple JPG image data stored in DCM file:

To avoid ambiguity, here's a little bit of an explanation. The scenario described in this blog post is: Suppose we have multiple JPG files in our hands and want to write JPG files to DCM files, that is, a single DCM file contains the Multi-frame form of multiple image information. This issue before with csdn Bo friends y317215133y also discussed, then I found a post in the Offis forum directly to y317215133y reply. Today I combed the discovery, then the situation in the post is slightly different from what I am going to describe today: the author of the Post already has the original data of multiple images (the data is uncompressed from the author's description) and wants to write the series data in the DCM file in compressed form. Presumably the author is doing this to reduce storage space, and I have JPEG compressed data in this blog post, which means I'm not trying to reduce storage space, but simply want to save multiple JPEG format images into the Multi-frame DCM format for easy archival management.

In the post, the Offis DICOM team's response is:1) Create Dcmfileformat object, use GetDataSet () to obtain the data body pointer;2) Use the dataset in Putandinsertxxx to 1 to write uncompressed raw image data, that is, the previous blog post dicom medical image processing: dicom storage operation of "multiple BMP image data into the DCM file" method;3) Register the JPEG encoding parameters, such as dj_prlossless, Dj_rplossy, and so on, and then call the Chooserepresentation function. This part of the operation is to the DCM file JPEG lossy or lossless compression, the specific process can refer to the code in dcmcjpeg.cc,4) call the SaveFile function to write the encoded data to Multi-fram DCM file.

The above four steps do not use the Dcmpixelsequence class, the post author and Bo friends y317215133y in this scenario but want to use dcmpixelsequence to learn about the sq field write operations, In fact, choosing a scene error will result in the error using the Dcmpixelsequence class. At the end of the post the author also gives hints such as:


This is what this article is going to do, I hope that this example to explain the use of Dcmpixelsequence class, and further learning JPEG compressed multi-frame DCM files.

code Example:

Referring to the code http://forum.dcmtk.org/viewtopic.php?t=1544&highlight=creating+multiframe+dicom+images in the Offis forum, directly to the source code:

DcmPixelDataTest.cpp: Defines the entry point of the console application. #include "stdafx.h" #include "dcmtk/config/osconfig.h" #include "dcmtk/dcmdata/dctk.h" #include "dcmtk/dcmdata/ Dcistrmf.h "#include" dcmtk/dcmdata/dcpixel.h "#include" dcmtk/dcmdata/dcpixseq.h "#include" dcmtk/dcmdata/ Dcpxitem.h "/*----BMP image parsing----*/#include" dcmtk/dcmdata/libi2d/i2dbmps.h "#include" DicomUtils.h "/*----JPEG image parsing---- */#include "dcmtk/dcmdata/libi2d/i2djpgs.h" #include "dcmtk/dcmdata/libi2d/i2doutpl.h" #include "dcmtk/dcmdata/ Dcerror.h "#include <direct.h>int _tmain (int argc, _tchar* argv[]) {ofcondition Status;dcmfileformat fileformat;d cmdataset* mydatasete=fileformat.getdataset ();D icomutils::adddicomelements ((dcmdataset*&) mydatasete); Uint16 rows,cols,sampleperpixel,bitsalloc,bitsstored,highbit,pixelrpr,planconf,pixaspecth,pixaspectv;ofstring Photometrint; Uint32 length; E_transfersyntax Ts;char curdir[255];getcwd (curdir,255);D cmpixelsequence *seq=new dcmpixelsequence (DcmTag (DCM_ PIXELDATA,EVR_OB));/*!------zssure:begin, add an empty dicom PixEl Item acts as offset Fragment------! *///seq->insert (New Dcmpixelitem (Dcmtag (DCM_ITEM,EVR_OB)));/*-------Zssure:end, Can successfully solve the problem of multiple JPEG in DCM-------------------------*///loop add 4 pictures for (int i=0;i<4;++i) {ofstring Num;char numtmp[255]; memset (numtmp,0,sizeof (char) *255); sprintf (numtmp, "%s\\jpeg-test\\%d.jpg", curdir,i+1); Ofstring filename=ofstring (numtmp); i2djpegsource* bmpsource=new I2djpegsource (); bmpsource->setimagefile (filename); char* PixData=NULL; Bmpsource->readpixeldata (ROWS,COLS,SAMPLEPERPIXEL,PHOTOMETRINT,BITSALLOC,BITSSTORED,HIGHBIT,PIXELRPR, Planconf,pixaspecth,pixaspectv,pixdata,length,ts);D cmpixelitem *newitem=new Dcmpixelitem (DcmTag (DCM_Item,EVR_OB) ); if (newitem!=null) {Seq->insert (newitem); Ofcondition Result=newitem->putuint8array ((Uint8*) pixData,length );} Delete Bmpsource;}; Mydatasete->putandinsertuint16 (Dcm_samplesperpixel,sampleperpixel); Mydatasete->putandinsertstring (DCM_ Numberofframes, "4"); Mydatasete->putandinsertuint16 (dcm_rows,rows); Mydatasete->putandinsertuinT16 (Dcm_columns,cols); Mydatasete->putandinsertuint16 (Dcm_bitsallocated,bitsalloc);mydatasete-> PutAndInsertUint16 (dcm_bitsstored,bitsstored); mydatasete->putandinsertuint16 (dcm_highbit,highbit); Mydatasete->putandinsertofstringarray (Dcm_photometricinterpretation,photometrint); Mydatasete->insert (seq , offalse,offalse); Status=fileformat.savefile ("C:\\MULTIJPEG2MULTI-FRAMEDCMTEST-ERROR.DCM", TS); if (Status.bad ()) {std::cout<< "Error: (" <<status.text () << ") \ n";} return 0;}
Ps:dicomutils class is the Dicom file operation static class, concrete see follow-up project source code.

The above code can successfully generate the Multi-frame DCM file, and the result should be normal from the file size. However, when opened, it prompts "memory cannot read error", such as:

But oddly enough, the Dcmdump.exe tool and the preview window of the Sante DICOM editor (Enable Icons) can see normal results. As shown in the following:


Error Analysis:JPEG compression in the DICOM standard

The JPEG compression format commonly used in the protocol is given in appendix A of part 5th of the DICOM3.0 standard, such as:

The common JPEG image is 1.2.840.10008.1.2.4.50, this is the format of the four pairs of test images given by this blog post. For JPEG specific compression and coding procedures, refer to wiki encyclopedia Http://zh.wikipedia.org/zh-cn/JPEG.

The standard indicates that if the Dicom file is of type multi-frame, each image (frame) needs to be compressed separately (encoded seperately). Compressed data may be fragmented when written to the Dcmpixeldata field in Dicom (fragment), remember that the data in each fragment (fragment) must come from the same file (that is, frame), Each image (frame) is not necessarily stored in the same fragment (fragment), so the correspondence between frame and fragment is "one-to-many".

dcmpixeldata Field (7fe0,0010):

DICOM3.0 the 5th part of the 8th chapter points out that if the data is stored in compressed form, then the Pixeldata VR can only use OB (raw data storage is usually used OW, if the data storage bit is less than or equal to 8 can also use OB form, as my previous blog post. Compressed data is split into multiple fragments (fragments) containing its own length, ending with a cutoff (FFFE,E0DD). As shown in the following:

An image (frame) can be contained in a fragment (fragment), or it can be segmented into multiple fragments. When used, it can be judged by comparing "field numberofframes (0028,0008)" with "Item number 1" in field Pixeldata.

Numberofframes==itemsofpixeldata-1, indicating that each image is contained in a fragment (fragment);

Numberofframes<itemsofpixeldata-1, indicating that there is an image is divided into multiple fragment storage;

Solution:

Note that the items in the Pixeldata field need to be "minus 1", as shown in table A.4-1, A.4-2, and in any case the Pixeldata field will contain an offset item. --That's why we have the above code error, to prove this, let's add an empty dcmpixelitem before inserting each image, i.e. add the following two lines of code before the For loop :

/*!------Zssure:begin, add an empty dicom Pixel item to act as offset Fragment------! */seq->insert (New Dcmpixelitem (Dcmtag (dcm_ ITEM,EVR_OB));/*-------zssure:end to solve the problem of multiple JPEG in DCM-------------------------*/

Now with the Dicom browser you can open the MULTIJPEG2DCMTEST.DCM that we generated, as shown in:



Using the binary viewer, you can see that the Pixeldata field has more than one sq Item, which is an empty dcmpixelitem that acts as offset, as shown in:



In addition, as can be seen from the final file size, this approach does not reduce storage space.



remark:

The compression method and storage mode of DCM data are given in the DICOM3.0 standard, and the application value of compressed data (lossy compression, such as the 1.2.840.10008.1.2.4.50 used in this example) is not considered in the protocol.


PS: Today accidentally back to the school, found that the original annual grind, see everyone in the cold weather in the exam outside the examination, sincerely wish you can test into their ideal school, (^ω^).

Follow-Up blog introduction:

Fo-dicom building a simple dicom Server service side




[email  Protected]

Date: 2014-12-27

DICOM Medical Image processing: "Multiple JPG image data stored in DCM files" by Dicom storage operations

Related Article

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.