DICOM Medical image processing: Orthanc Plugin SDK for Wado services

Source: Internet
Author: User

Background:

Orthanc is one of the best open source software for DICOM and HTTP services found by bloggers, and some of the basic uses of Orthanc were described in the previous sections. Orthanc from the 0.8.0 release of the plugin SDK, through which the Orthanc built-in rest API to implement the Wado service, the following reference to the official website gives a description of how to use the SDK to implement the Wado service, and to update the official website instance , using the latest approach to directly implement Wado services.

Official Description Chinese Translation: 1) Introduction

The DICOM standard defines the file format as well as the medical Image Network transport protocol. WADO, the Web Access to DICOM persistent Objects, is a protocol for accessing medical images based on Web services in the DICOM3.0 standard (specifically in DICOM3.0 part 18th). Through the Wado protocol, professional physicians can preview and download medical images using common browsers (currently Orthanc does not seem to support IE).

The code attached to this post provides an example of implementing a simple Wado service. The example can return the original dicom image, or JPEG format image, and can be run as a plug-in for Orthanc. With the help of the Orthanc framework, the Wado service can be implemented in a few simple lines of code.

2) Background:

The Orthanc is an open source, lightweight, standalone, and supports a scripted dicom server. Orthanc is mainly used to streamline clinical procedures and simplify the management of medical images. In addition, by compatible with common JSON, PNG format and restful API, DICOM standard has been widely used in computer image field. Orthanc hides the complexity of the Dicom file format and DICOM protocol, so the hospital's general network managers and professional medical image automatic analysis software developers can use. Orthanc can serve as a robust medical imaging center for each hospital.

Starting with 0.8.0 (released from July), Orthanc has provided plug-in development SDKs for external developers. Plug-ins developed using the SDK can be imported into the Orthanc service, which responds to the browser's HTTP requests by registering a callback function. The callback function, in turn, accesses the Orthanc database to extract information from the target dicom file. The Orthanc Plugin SDK is given in the form of a C language header file, with the following links: https://code.google.com/p/orthanc/source/browse/Plugins/OrthancCPlugin/ orthanccplugin.h?name=orthanc-0.8.0, instruction document: http://www.codeproject.com/KB/webservices/797118/ Orthancplugindocumentation.zip

3) DICOM and WADO

This section provides an overview of the Wado protocol, which is described in detail in part 18th of the DICOM3.0 standard.

The DICOM protocol stipulates the following criteria: a patient (Patient) can do multiple examinations (studies). Each inspection (Study) contains a series of medical images, namely sequences (series). For example: The standard pet-ct check (Study) contains two sets of sequences, CT sequence and pet sequence. A two-dimensional/three-dimensional/four-dimension image of the human body usually corresponds to a sequence. Each image is segmented into multiple file stores, the instance (which is the single file suffix DCM that we see that contains one image).

Typically, a dicom instance (Instance) can be seen as a combination of two-dimensional images and a structure that stores patient meta information (demographic information such as name, age, height, weight, and so on). The patient meta information is usually an array containing the corresponding values of the dicom tag. Each label is represented by a two hexadecimal number. It is very important that each level of inspection (Study), Sequence (series), and image (Instance) require global uniqueness.

For example (0x0020,0x000d) represents the Study Instance UID, which defines the uniqueness of the check (Study);

............

A Wado request is a simple HTTP GET request with the study, series, and instance identifiers included in the request. For example:

Http://localhost/wado?    studyuid=1.2.840.113845.11.1000000001951524609.20121203131451.1457891&    seriesuid= 1.2.840.113619.2.278.3.262930758.589.1354512768.115&    objectuid= 1.2.840.113619.2.278.3.262930758.589.1354512768.116.1&    Requesttype=wado

The response of the Wado request will be the JPEG format of the dicom image corresponding to the studyuid/seriesuid/objectuid. If you want to get the dicom format file directly, you should add contenttype=application%2fdicom to the Wado request as follows:

Http://localhost/wado?    studyuid=1.2.840.113845.11.1000000001951524609.20121203131451.1457891&    seriesuid= 1.2.840.113619.2.278.3.262930758.589.1354512768.115&    objectuid= 1.2.840.113619.2.278.3.262930758.589.1354512768.116.1&    contenttype=application%2fdicom&    Requesttype=wado
    
Official instructions for a simple translation here, the following is a combination of specific examples of the way to proceed. Orthanc WADO plugin Edit and use:

The sample code relies on the following four parts: the Orthanc Plugin SDK (after the 0.8.0 version), CIMG library (for converting DICOM images to PNG format), and jsoncpp libraries for parsing the JSON-formatted files returned by the Orthanc service ; CMake, used to compile the source code.

1) Compilation of Orthanc WADO plugin:

Download the source code in the official note (http://www.codeproject.com/KB/webservices/797118/ Wadopluginsources.zip), after decompression, follow the instructions in README.txt to compile and install Orthanc WADO Plugin:

First step: Go to cmd command line mode, create compile directory, enter command: mkdir build

Step two: Go to the build directory

Step three: Start CMake, start compiling, enter CMake. \wadopluginsources ( Note: here.) It means to return to the directory where CmakeList.txt is located in the Wadopluginsources source code, which is wrong in README.txt .

Fourth step: Open the WadoPlugin.sln project under the build directory and compile with VS, you will see the WadoPlugin.dll in the Build\debug directory, indicating that the Wado plug-in was generated successfully.

2) Installation of Orthanc WADO plugin:

README.txt the installation instructions given in the source package is incorrect, you should add the WadoPlugin.dll full pathname to the plugin corresponding field in the Configuration.json file, as shown in:

Note: The path of the WadoPlugin.dll entered in the Windows system should use "/" in, or enter "C:\\wadopluginsources\\build\\debug\\wadoplugin.dll". Otherwise, an error will occur.

3) Orthanc WADO plugin start:

After modifying the Configuration.json file, go to the directory where Orthanc.exe, for example, my machine is: C:\orthanc-0.8.5\debug>orthanc.exe. /.. /orthanc/configuration.json. Note: followed by the path of the Configuration.json that added the WadoPlugin.dll, if the input Orthanc.exe--config= Configuration.json, is the result of generating the default Configuration.json, and does not start the Wadoplugin service).

4) Example test:

According to the previous blog post, upload two test images, the results are as follows:

The levels of the known test1 UID are:

studyinstanceuid=1.3.6.1.4.1.30071.6.176694098609799.4240639413125000;

seriesinstanceuid=1.3.6.1.4.1.30071.6.176694098609799.4240639413125000.1;

sopinstanceuid=2.16.840.114421.81623.9430067258.9493139258;

Constructs the Wado request, queries the test1 image, requests the connection as follows: http://localhost:8042/wado?studyUID= 1.3.6.1.4.1.30071.6.176694098609799.4240639413125000&seriesuid= 1.3.6.1.4.1.30071.6.176694098609799.4240639413125000.1&objectuid= 2.16.840.114421.81623.9430067258.9493139258&requesttype=wado

The browser results are as follows, as in the TEST1.DCM original file.

New Orthanc WADO plugin:1) Official description:

There is a paragraph in the official statement: (HTTP://WWW.CODEPROJECT.COM/ARTICLES/797118/IMPLEMENTING-A-WADO-SERVER-USING-ORTHANC)

When the study/series/instance identifier is resolved from the Wado HTTP request, it needs to be queried in the Orthance database. To implement query targeting, the code instance given by the official blog post borrows directly from the Orthanc built-in RESTful API service (rather than responding directly to Wado HTTP requests).

First you need to locate the study level, the code is as follows:

[CPP]View PlainCopyprint?
  1. Static bool Locatestudy (json::value& study,
  2. Const std::string& STUDYUID)
  3. {
  4. //Retrieve The list of the studies that is stored in Orthanc
  5. Json::value listofstudies;
  6. if (! Orthanccontext::getinstance (). Restapidoget (Listofstudies, "/studies"))
  7. {
  8. return false;
  9. }
  10. //Retrieve information about each of the these studies
  11. For (Json::value::arrayindex i = 0; i < listofstudies.size (); i++)
  12. {
  13. std::string Studyuri = "/studies/" + listofstudies[i].asstring ();
  14. if (Orthanccontext::getinstance (). Restapidoget (study, Studyuri))
  15. {
  16. //If the "studyinstanceuid" of this study matches, we is done
  17. if (study["Maindicomtags"] ["Studyinstanceuid"].asstring () = = Studyuid)
  18. {
  19. return true;
  20. }
  21. }
  22. }
  23. return false;
  24. }

The Locatestudy function constructs a URI request for the/studies form of the RESTful API, queries all the study UUID in the Orthanc, and then loops through each of the obtained studyuuid, constructing/studies/{id } form of RESTful API request, one by one to return the JSON results in the STUDYINSTANCEUID tag, to achieve study positioning;

Second, locate the Sereis level, the code is as follows:

[CPP]View PlainCopyprint?
  1. Static bool Locateseries (json::value& series,
  2. Const json::value& Parentstudy,
  3. Const std::string& SERIESUID)
  4. {
  5. //Loop over the child series of the located study
  6. const json::value& listofseries = parentstudy["Series"];
  7. For (Json::value::arrayindex j = 0; J < Listofseries.size (); j + +)
  8. {
  9. std::string Seriesuri = "/series/" + listofseries[j].asstring ();
  10. //If the "Seriesinstanceuid" of this series matches, we is done
  11. if (Orthanccontext::getinstance (). Restapidoget (series, Seriesuri) &&
  12. series["Maindicomtags" ["Seriesinstanceuid"].asstring () = = Seriesuid)
  13. {
  14. return true;
  15. }
  16. }
  17. return false;
  18. }

Similar to the study level;

Finally, the instance level, the code is as follows:

[CPP]View PlainCopyprint?
  1. Static bool Locateinstance (json::value& instance,
  2. Const json::value& Parentseries,
  3. Const std::string& OBJECTUID)
  4. {
  5. //Loop over the child instances of the located series
  6. const json::value& listofinstances = parentseries["Instances"];
  7. For (json::value::arrayindex k = 0; k < listofinstances.size (); k++)
  8. {
  9. std::string Instanceuri = "/instances/" + listofinstances[k].asstring ();
  10. //If the "Sopinstanceuid" of this series matches "Objectuid", we is done
  11. if (Orthanccontext::getinstance (). Restapidoget (instance, Instanceuri) &&
  12. instance["Maindicomtags" ["Sopinstanceuid"].asstring () = = Objectuid)
  13. {
  14. return true;
  15. }
  16. }
  17. return false;
  18. }

The above positioning process is complex, since the 0.8.0 Release Orthanc provides direct access to the DICOM index in the database functions, Orthancpluginlookuppatient (), Orthancpluginlookupstudy (), Orthancpluginlookupstudywithaccessionnumber (), Orthancpluginlookupseries () and Orthancpluginlookupinstance (). Using this kind of function will need not first locate study, reposition series, and finally locate instance so cumbersome, the modified code is as follows:

[CPP]View PlainCopyprint?
  1. 2014-12-07:zssure
  2. Use the interface of the new Orthanc plug-in to directly locate the instance
  3. Http://www.codeproject.com/Articles/797118/Implementing-a-WADO-Server-using-Orthanc
  4. Static bool Locateinstance (json::value& instance, const std::string& objectuid)
  5. {
  6. char* instanceId = orthancpluginlookupinstance
  7. (Orthanccontext::getinstance (). GetContext (), Objectuid.c_str ());
  8. if (instanceId = = NULL)
  9. {
  10. return false;
  11. }
  12. std::string Instanceuri = "/instances/" + std::string (instanceId);
  13. Orthancpluginfreestring (Orthanccontext::getinstance (). GetContext (), instanceId);
  14. return (Orthanccontext::getinstance (). Restapidoget (instance, Instanceuri) &&
  15. instance["maindicomtags" ["Sopinstanceuid"].asstring () = = Objectuid);
  16. }
  17. Zssure:end



2) New Wado plugin modified:

According to the official instructions Orthanc Plugin SDK is given in the C header file format, Therefore, after replacing OrthancCPlugin.h in wadopluginsources with the OrthancCPlugin.h file in Orthanc-0.8.5, we found that the G in WadoPlugin.cpp function we added Etcontext () is not recognized:

Opening the OrthancContext.h file discovers that the GetContext () function does not exist in the file, so you need to add the public function manually:

[CPP]View PlainCopyprint?
    1. Public
    2. orthancplugincontext* GetContext ()
    3. {
    4. return context_;
    5. }



The GetContext () function is recognized after the modification is complete, but the following error occurs after compiling:

will include ".. /.. /resources/thirdparty/visualstudio/stdint.h "The code has been modified to include" stdint.h "to eliminate the above error. The new WadoPlugin.dll plugin can be obtained after rebuilding. Re-enter the Wado Request and get the following test results:

At this point Orthanc WADO plugin The development of the explanation is complete.

DICOM Medical image processing: Orthanc Plugin SDK for Wado services

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.