DICOM Medical Image processing: Orthanc,modification & anonymization of deconstructed PACs

Source: Internet
Author: User

background:

In the last blog post for the introduction, introduced a magical open source PACs system--orthanc. This article begins by interpreting the relevant content in the official cookbook, and for simple browsing, access and uploading please read the previous blog post. The modification and anonymity of DCM images has not been seen in conventional PACs systems, so this focus is on Orthanc's modification (modification) and anonymity (anonymization) of the DCM medical images using the rest API. Examples of official cookbook are demonstrated and debugged by Orthanc source analysis to ensure that the sample works well in this machine. Note : Examples in official cookbook will have errors under Windows, see blog post for details.

Orthanc Introduction:

Named Orthanc from J.R.R Tolkien's (Tolkien) novel. Orthanc is the black Tower of the Isengard (Isengard) fortress, which was first built in the second century, and is used to store the--palantíri of the southern Kingdom, a circle of stones that can be seen far away, Through the palantíri can communicate with people who use Palantíri in the distance. Orthanc server is taking the palantíri of this layer meaning, designed a convenient, transparent and programmable access to medical images in the entire hospital Dicom topology network (refer to wiki encyclopedia: http://en.wikipedia.org/ Wiki/isengard).

In addition, "RTH", or radiotherapy, is included in the Orthanc. In fact, Orthanc itself stems from a study of radiation therapy services at the Centre Hospitalier Universitaire, de Liège University, France.

Orthanc of modification & anonymizationanonymization:

Orthanc has introduced an anonymous operation of DICOM resources since version 0.5.0, which can be anonymized for patients (patients), check (studies), Sequence (series), and image (instances) at multiple levels. For illustrative purposes, the instances level is described here:

1) upload two test images to Orthanc Server as shown in the previous post:


2) using the Curl command line to view the above two instances, get the ID number, the result is as follows:

Curl Http://localhost:8042/instances

The instance ID number obtained here is:c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c

3) Anonymous operation according to Orthanc official Cookbook's Instructions

Input instructions: Curl Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/anonymize-X post-d ' {} ' > C:\ORTHANC-ANONYMIZE.DCM

But did not get the expected results, open the C drive found that the orthanc-anonymization.dcm file size is 0KB. Turn on Curl's verbose mode,

Curl–v Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/anonymize-X post-d ' {} ' > C : \ORTHANC-ANONYMIZE.DCM

View the output information as follows:


The HTTP service return value in Orthanc server was found to be 404.

Through their own view of the official cookbook instructions, in addition to the corresponding instance UID different, did not find the problem, for the moment skip, try modification.


Modification:

1) Upload DCM files to Orthanc Server, same as in anonymization;

2) Use Curl Http://localhost:8042/instances to obtain the ID number of the specified instance;

3) Modification treatment with reference to official cookbook


Enter the following instructions, this time for convenience, directly using Curl's verbose mode:

Curl–v http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/modify–x post–d ' {"Replace": { "Patientname": "Hello", "Patientid": "World"} ' >C:\ORTHANC-MODIFY.DCM

The output results are as follows:


So far, the two examples given by the official cookbook of Orthanc have not been able to be completed successfully in this machine. So guess the code given in the official website may be a Linux system, the Windows system should make the appropriate adjustments, but how to adjust it? Which part of the adjustment? Please keep looking down ...

Debug Orthanc Official Cookbook Example:0) Orthanc REST API data query:

Before debugging, we need to understand the general cause of the problem, and eliminate some common errors, such as software version errors, spelling errors, and so on. The anonymization and modification described above take advantage of the rest API capabilities of Orthanc, so what is the level of support for the rest API for Orthanc versions? Let's take a look at the official note, as shown in:


As you can see, Orthanc supports multiple levels of modification and anonymity since version 0.5.0, as described in the previous post, I have installed the latest version of 0.8.5. As a result, you can ensure that the software version is correct, and we have also checked spelling errors during the example simulations.

Then we have to do our killer: "Start C:\Orthanc-0.8.5\Orthanc.sln project, enter the debug mode, view the source code of Orthanc"

Open the Orthanc.sln solution, right-Orthanc the project to open debug mode, insert a breakpoint in several core classes about the rest API, and the first attempt to insert a breakpoint is as follows:

1) anonymization source debugging:

By following the steps in the previous section, you first use Orthanc Explorer to add dicom files to Orthanc server in debug mode, and then press F5 to skip debugging, because image loading is not a problem. ( note : This step must be re-added, because the storage directory for the data in debug mode is C:\Orthanc-0.8.5\OrthancStorage, unlike the default c:orthancstorage of the binary installation package, The images we added in the previous section are not visible in the debug state )


Enter the command to view the ID:

Curl Http://localhost:8042/instances

Start typing the anonymization directive from the previous section:

Curl-v Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/anonymize-X post-d ' {} ' > C : \ORTHANC-ANONYMIZE.DCM

The Orthanc project first stops in the visit function in the breakpoint RestApi.cpp, as shown in:

Using F11 single-step debugging, and then entering into the function Parseanonymizationrequest parsing the anonymization request operation, you can see that an example is given in the function that is the same as the format we entered


Continue the single-step debugging, finally found in parsing JSON format anonymizationrequest instruction, that we entered the ' {} ', json_reader.cpp in the Readtoken return value is tokenerror.

At this point we have found the anonymization instruction error reason, should be we input JSON format is not correct, although we are in accordance with the official Orthanc cookbook. To determine if our JSON format is wrong, test it on the online JSON format check site (http://www.bejson.com/) with the result:


Follow the prompts to remove the single quotation marks from the JSON part of the instruction and enter:

Curl-v Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/anonymize-X post-d {} > c \ Orthanc-anonymize.dcm

The result of the Curl debug output is:


Using DICOM to look at the software, open can be found in the ORTHANC-ANONYMIZE.DCM file of the patient name has been hidden away.


"Summary": the correct instruction should be to not add single quotes outside, as follows:

Curl-v Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/anonymize-X post-d {} > c \ Orthanc-anonymize.dcm

2) Modification source debugging:

Now that we've found the problem with the code in Anonymization, let's get rid of the single quotes in the modification and try this:

Input instructions:

Curl-v Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/modify-X post-d {"Replace": {" Patientname ":" Hello "," Patientid ":" World "} >C:\ORTHANC-MODIFY.DCM

To our disappointment, we still see the 404 error returned by HTTP server.


Since there are still more double quotes inside the single quotation mark in the modification directive, we continue to debug, depending on the previous experience, it is possible to input errors in JSON format, but we only keep json_ Reader.cpp in the Readtoken breakpoint, directly to see if the results of the resolution is Tokenerror? .

Re-enter the instruction and enter inside the Readtoken, and find that the function still returns TOKENERROR, as shown in the following:

Using the VS bring-on view tool, we can see the Readtoken function parsing the string current_, the actual content is: {Replace:{patientname:hello,patientid:world}}, We did not see the double quotes we entered, we entered {Replace:{patientname:hello,patientid:world}} into the http://www.bejson.com/, and got the wrong result hint:


This indicates that the double quotation marks in the JSON instruction we entered in the command line are ignored during the VS read-in process.

Then we use the escape character to pass in the double quotes, enter the instruction:

Curl-v Http://localhost:8042/instances/c77324ec-f5e76fc5-c96846bf-2ed4097d-86f9e79c/modify-X post-d {\ "replace\": {\ "patientname\": \ "hello\", \ "patientid\": \ "World\"}} >c:\orthanc-modify.dcm

View results:

The final run output is,


You can see that Patientid and Patientname have been modified by opening ORTHANC-MODIFY.DCM in the DCM view software.


At this point, about Orthanc modification and anonymization debugging has been successfully completed, can be relieved, or debug source code to force Ah ^_^.

Knowledge Point Supplement:

Orthanc as an open source project, getting its source code is naturally easy. Although it is known as a light server system, the amount of code is enough to scare most people. It's hard to debug a huge amount of code for the first time. Here's an example of how to start debugging an open source project using the anonymization and modification example procedures in the official cookbook of the above Debugs Orthanc:

1) How to debug the HTTP Server in Orthanc

The last section initially set breakpoints in the RestXXX.cpp file because the Benbovin modification and anonymization use the REST API service provided by Orthanc, so first speculate that the error should appear in the rest The associated implementation function of the API. This method can solve the problems we encountered above, and as you see, we have implemented the problem of troubleshooting.

But since the debugging into the Orthanc source, it is Shundaur to figure out the overall process of the HTTP server Orthanc, but also in the way to find out in which place the curl instructions in the double quotation marks ignored.

Once again, enter the instruction and enter the debug state. Breakpoint first stop in RestApi.cpp in the visit function, in the previous section we use "Single Step debugging" smooth step into the JSON's analytic function Readtoken, "single-Step Debugging" is the best way to trace forward, It is also the most intuitive and advantageous error-checking tool that VS offers to us. But in order to understand the whole process, we need to "backtrack" here, what is the tool that VS provides to us upstream? That is "Find all references" as shown in:

We can move from RestApi.cpp to the upper level, the Lookupresource function in RestApiHierarchy.cpp, so that this iterative belief can go back to the top of the entire process. Although this method is clumsy, it is more practical.

Presumably in the Windows programming environment, people still prefer the intuitive operation of "visualization", that is, WYSIWYG. Then click "Debug" in the menu bar, select "Call stack" in window, you can visually see the various function call order before the visit function in RestApi.cpp, as shown in:

At this point we can see that the entire HTTP Server service starts with the Worker_thread function in Mongoose.cpp (in the call stack, right-click "go to Source" to see where the function is located). In the order of "call stacks" we can clearly see the entire invocation process of the Orthanc Http server. So we insert a breakpoint in the Worker_thread function, re-enter the curl instruction, and look at the starting state of the whole process, what is the format of the data body received by Orthanc Http server? As shown in the following:

When reading the POST request instruction from curl inside the process_new_connection function, there is no longer a double quote in the contents of the connection cache buf, so you can determine the-d parameter of Curl to send JSON-formatted data to Orthanc HTTP The double quotation marks are omitted from the server. Later, you can look at the use of curl in Windows, especially the-d parameter settings.

2) How to debug the Dicom Server in Orthanc

Because DICOM server is more familiar, prior knowledge is more, so debugging is easier than HTTP server. In the main function of Orthanc we can see Httpserver.start () and Dicomserver.start (), and Dicomserver.start () is the entry point of Dicom server. Since Orthanc is developed based on DCMTK, the subsequent process should be done by DCMTK, and more detailed details can be found in the DCMTK network series earlier in this column. In addition to the next Boven detailed introduction of the use of fo-dicom Open Source Library to create a simple dicom Server service side, then detailed analysis of the Orthanc in the DICOM server, please look forward to.

References:

Https://code.google.com/p/orthanc/wiki/OrthancCookbook,Cookbook website Link

Https://code.google.com/p/orthanc/wiki/Anonymization,Orthanc's modification and anonymization introduction

https://docs.google.com/spreadsheet/pub?key=0ao5armxcx2hldejadzvuawfmnw5qtwhryti3uhmzdxc&single=true& Gid=8&output=html,rest API Support Map

https://docs.google.com/spreadsheet/pub?key=0ao5armxcx2hldejadzvuawfmnw5qtwhryti3uhmzdxc&single=true& Gid=0&output=html,rest API Support Map

Next Column blog post trailer:

Fo-dicom building a simple dicom Server



" Span style= "font-family: Microsoft Jacob Black; font-size:18px; Color: #0000ff "> [email  Protected]

Date: 2014-11-29

DICOM Medical Image processing: Orthanc,modification & anonymization of deconstructed PACs

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.