DCMTK Open Source Library Learn Note 4: Archiving DCM images with INI configuration files

Source: Internet
Author: User

Ext.:http://blog.csdn.net/zssureqh/article/details/8846337

Background introduction:

The service side of medical Image PACs workstation needs to archive a large number of DCM files and write database processing. Because of the particularity of medical images, each patient (i.e., the so-called patient) will produce at least one set of image sequences (i.e., the series) for each examination (i.e., study), and each group of image sequences will contain a large number of DCM files (for example, a heart CTA diagnosis, A complete heart scan sequence has about 200 images). Each image in the DICOM3.0 protocol is labeled with a specific three UID (unique identifier), namely Studyinstanceuid, Seriesinstanceuid, Sopinstanceuid. Where Studyinstanceuid represents the only one check (Study), Seriesinstanceuid represents the unique sequence (series) under the corresponding check, and the Sopinstanceuid represents the only image under the unique sequence under the unique check. Typically, PACS workstations use these three UID to archive DCM files.

The design of the archive:

1. The basic archive structure is:

First level: studyinstanceuid

Store image data for the same patient

Level two: Seriesinsta Nceuid

Stores the image data under the same check

Level three: S Opinstanceuid

Stores image data under the same sequence

Once you understand the approximate archive structure, you should now consider how to write DCM records to the database. The most intuitive idea is to record each DCM file in the database so that it can be queried directly in the database with a given three UID when the specified DCM file needs to be read. However, the capacity of the database increases sharply, and the same patient has a large number of redundant records in the database. Because the patient's image data is archived according to the above level three directory, a large number of related image data are stored in the same directory of the server, the image of the same sequence can be retrieved directly in the second level directory using Sopinstanceuid, without the need for database queries. But when the number of files in the level two directory is large, retrieving files in the file also takes a lot of time, so how can you improve the efficiency of retrieval? The answer is: Config file. Since we have read the three UID of each DCM file at the time of filing, we can write the UID information read in the archive to the corresponding INI configuration file and store it in the corresponding image sequence directory. Then when retrieving the image, through the first two level UID can quickly in the database to query the image data archive directory, when entered into the specified archive directory, using the INI file generated by the archive, can quickly retrieve the specified DCM file, In addition, if you archive some of the commonly used DCM file information together into the INI configuration file (like width, height, patient name, date of birth, window width/window, etc.), in some subsequent image processing can also save time and improve efficiency.

2. ini configuration file generation

INI configuration file format is not detailed, CSDN has a lot of detailed explanation of the blog, please see for yourselves. This is a detailed explanation of how to use the DCMTK Open Source Library to extract the appropriate DCM file information and write it to the INI configuration file.

DCMTK Open Source Library is a good basic library of medical imaging development, it implements the DICOM3.0 standard very well, and the inheritance system of class is simple and clear, corresponding to DICOM3.0 standard one by one (then writes about "DCMTK Open Source Library's inheritance system and DICOM3.0 standard correspondence" 's blog post). Here we only use the Dcmitem class in DCMTK, which derives from the Dcmobject base class, which contains a elementlist member variable that stores the basic structure of a series of data elements specified in the DICOM3.0 standard as shown in:



Note: The Dcmitem class is a subclass of a dataset (a dataset). The inside contains a sequence of data elements (that is, elementlist data members).

By reading the source code of the Dcmitem class, we summarize the following functions of the DCMTK open Source Library to manipulate the corresponding data elements of the DCM file: findandget function, findorcreate function, findandxxx function, Putandinsert function, and INSERTXXX functions, such as:

At this point we can use the Findandget function class to extract the relevant information in the DCM file, and combine the WINDOWSAPI function to archive the INI configuration file. Since the INI configuration file is a text file, we have chosen the findandgetstring function in Dcmitem to extract the data elements in the DCM file, using the Findandgetstring function to directly get the string format (const char* ), in addition, the WritePrivateProfileString function is combined to generate the INI configuration file. (Note: Here the Findandgetstring function matches exactly the format of the WritePrivateProfileString function, if other functions of findandget, such as FindAndGetSin32, are used, It is necessary to use ITOA and other functions to convert an integral type to a const char* type, increasing the complexity of programming)

Some of the code is given below:

[CPP]View Plaincopyprint?
  1. Dcmtagkey thu_dcm_elements[]=
  2. {dcm_instancenubmber, dcm_rows,dcm_columns,dcm_patientname}; //define a DCM Data element label array to be written to the INI file
  3. int num=sizeof (thu_dcm_elemnts)/sizeof (Dcmtagkey);
  4. Ofstring Mimagevalue;
  5. Ofstring mgap ("|"); //ini between individual data elements in a configuration file
  6. Ofstring mimagemodule ("imagemodule\\"); section name of the configuration file
  7. Ofstring Msopinstanceuid;
  8. Ofstring Mseriesinstanceuid;
  9. Dcmdataset *pdataset=mdcmfile->getdataset ();
  10. Dcmmetainfo *pmetainfo=mdcmfile->getmetainfo ();
  11. Pdataset->findandgetofstring (DCM_SERIESINSTANCEUID,MSERIESINSTANCEUID);
  12. Pdataset->findandgetofstring (DCM_SOPINSTANCEUID,MSOPINSTANCEUID);
  13. Mimagemodule+=mseriesinstanceuid;
  14. for (int i=0;i<num;++i)
  15. {
  16. Ofstring Mvaluerecord;
  17. Dcmelement *element;
  18. if (Thu_dcm_elemnts[i].getgroup () >0x0002)//To determine if the thu_dcm_elements[i] is metainfo
  19. {
  20. //the element belongs to Dataset
  21. Pdataset->findandgetofstringarray (Thu_dcm_elemnts[i],mvaluerecord);
  22. Mvaluerecord+=mgap;
  23. }
  24. Else
  25. {
  26. //the element belongs to MetaInfo
  27. if (Thu_dcm_elemnts[i].getgroup () ==0x0000 && thu_dcm_elemnts[i].getelement () ==0x0000)
  28. {
  29. Mvaluerecord=mgap;
  30. }
  31. Else
  32. {
  33. Pmetainfo->findandgetofstringarray (Thu_dcm_elemnts[i],mvaluerecord);
  34. Mvaluerecord+=mgap;
  35. }
  36. }
  37. Mimagevalue+=mvaluerecord;
  38. }
  39. :: WritePrivateProfileString (Mimagemodule.c_str (), Msopinstanceuid.c_str (), Mimagevalue.c_str (), iniFileName);

3, the database writes:

The way the database is written is basically similar to the INI configuration file generation, as long as the people who know a little about C + + database programming can easily follow the configuration of the INI profile to complete the database write section, which is not detailed here, just give a simple part of the code:

[CPP]View Plaincopyprint?
  1. Dcmfileformat FileFormat;
  2. TCHAR Filepath[max_path];
  3. Ofcondition oc = Fileformat.loadfile (FilePath);
  4. Dcmdataset *pdataset=fileformat.getdataset ();
  5. Char query[1000];
  6. memset (query,0,sizeof (char) *1000);
  7. Lstrcat (query,_t ("INSERT into patient values ("));
  8. Const Char *tstring;
  9. Pdataset->findandgetstring (dcm_instancenumber,tstring);
  10. Lstrcat (query,tstring);
  11. Lstrcat (query,_t (","));
  12. Pdataset->findandgetstring (dcm_patientname,tstring);
  13. Lstrcat (query,_t ("\" "));
  14. Lstrcat (query,tstring);
  15. Lstrcat (query,_t ("\" "));
  16. Lstrcat (query,_t (","));
  17. Pdataset->findandgetstring (dcm_patientid,tstring);
  18. Lstrcat (query,tstring);
  19. Lstrcat (query,_t (","));
  20. Pdataset->findandgetstring (dcm_patientbirthdate,tstring);
  21. Lstrcat (query,tstring);
  22. Lstrcat (query,_t (","));
  23. Pdataset->findandgetstring (dcm_patientsex,tstring);
  24. Lstrcat (query,"\");
  25. Lstrcat (query,tstring);
  26. Lstrcat (query,"\");
  27. Lstrcat (query,",");
  28. Pdataset->findandgetstring (dcm_patientage,tstring);
  29. Char temp[100];
  30. memcpy (Temp,tstring,lstrlen (tstring));
  31. Temp[lstrlen (tstring)]=_t (' n ');
  32. for (int I=0;i<strlen (temp); ++i)
  33. if (temp[i]==_t (' Y '))
  34. temp[i]=_t (' n ');
  35. Lstrcat (query,temp);
  36. Lstrcat (query,",");
  37. Lstrcat (query,_t ("2013)");
  38. n style=write to "White-space:pre" > </span>//mysql Database
  39. mysql* con;
  40. Con=mysql_init ((mysql*) 0);
  41. if (Con!=null && mysql_real_connect (Con,host,user,passwd,db,port,unix_socket,client_flag))
  42. {
  43. if (!mysql_select_db (con,db))
  44. {
  45. ::p rintf ("Selcet successfully the database!\n");
  46. con->reconnect=1;
  47. int rt=mysql_real_query (mysql,query,strlen (query));
  48. if (RT)
  49. {
  50. ::p rintf ("Error making Insert!!!  \ n ");
  51. }
  52. }
  53. }

for MySQL C + + operations, see the blog post: http://www.cnblogs.com/justinzhang/archive/2011/09/23/2185963.html

DCMTK Open Source Library Learn Note 4: Archiving DCM images with INI configuration files

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.