Project HIBASTIMAM Part 11: Preparing for DICOM Inference

Brad Genereaux
5 min readMay 3, 2020

In my eleventh article of this series, How I Built a Space to Train and Infer on Medical Imaging AI Models (HIBASTIMAM), I will cover how I set up my home computer to be DICOM ready for running end-to-end PACS-centric inference. Check out Part 1 for what this series is about, which also has links to the other parts.

Preparing for DICOM Inference

In this post, we’re going to set up a few different aspects of DICOM, so that we are ready to connect a Clara inference pipeline into a medical imaging workflow. It will consist of a few different parts — setting up a PACS (in this case, Orthanc), and transforming our test image into a DICOM file, loading it into Orthanc, and viewing it. That’ll be success for this post.

Before continuing, please review the important disclaimer in Part 1.

Photo by Sai Kiran Anagani on Unsplash

For this blog, I’m listening to Apple’s ALT CTRL playlist. Don’t forget to take frequent breaks. This is a blog of mini-achievements — building up to something great here.

Let’s do it!

Concepts

DICOM is the standard for medical imaging file structure and transmission. This blog assumes you know what you need to know about DICOM — but if you want to learn more, check out the DICOM homepage. There’s also some videos on Vimeo and Youtube that walks through DICOM concepts — here’s a video from FHIR DevDays 2018:

In this blog post, we are using Orthanc as our DICOM repository. Orthanc is great for the purpose of this blog, and it makes the DICOM interactions easy, since we can POST them using web APIs. Any medical imaging repository that supports DICOMweb STOW should be capable of this — but there may be caveats that you would have to consider — including handling any security / authentication / authorization. Outside of Orthanc, DCM4CHEE is another excellent DICOM environment to experiment with.

Installing Orthanc

Let’s open a Terminal, and get Orthanc installed. This is a simple step:

sudo apt-get install orthanc

You may have to confirm certain libraries are installed — but it is a quick install. You can test it out by opening a browser to port 8042; go to http://localhost:8042 and see what happens. You should have an empty patient database.

Explore the Orthanc cookbook for everything you can do with Orthanc.

Installing DCMTK and other libraries

On my computer, I already had DCMTK installed — so it is likely it is included with one of the other downloads; but to be certain, check with apt-get:

sudo apt-get install dcmtk
sudo apt-get install imagemagick
sudo apt-get install dicom3tools

Creating a DICOM Test File

Next, let’s take our sample test file from Part 10, and turn it into a DICOM file. Let’s create a working directory in our experiments folder:

mkdir /etc/clara/experiments/makedicom

We can use a tool provided by DCMTK, called img2dcm, to convert the image. It only accepts JPGs, so we need to first convert our PNG to JPG.

convert /etc/clara/operators/app_covidxray/input/1-s2.0-S0929664620300449-gr2_lrg-b.png /etc/clara/experiments/makedicom/1-s2.0-S0929664620300449-gr2_lrg-b.jpg

Next, we will use img2dcm to create our DICOM file. DICOM has a variety of required metadata tags to populate — and we can specify them on the command line, but it will be long. That’s okay — let’s create it:

img2dcm /etc/clara/experiments/makedicom/1-s2.0-S0929664620300449-gr2_lrg-b.jpg /etc/clara/experiments/makedicom/testdicom.dcm -k "PatientName=PATIENT^TEST" -k "StudyDate=20200501" -k "StudyTime=090000" -k "SeriesDate=20200501" -k "SeriesTime=090000" -k "PatientID=123456" -k "PatientBirthDate=19700101" -k "AccessionNumber=20200501-01" -k "StudyID=20200501-01" -k "ReferringPhysicianName=BLOG^HIBASTIMAM" -k "PatientSex=M" -k "Modality=XC" -k "SeriesNumber=1" -k "InstanceNumber=1" -k "BodyPartExamined=CHEST"

Now, it is good practice to check the DICOM instance and validate it. We will use a tool from dicom3tools called “dciodvfy”:

dciodvfy /etc/clara/experiments/makedicom/testdicom.dcm

If all goes well, this should only tell you the type of object it is. If you get more than that, the command above will have to be manipulated to add the missing context.

Importing our DICOM file into Orthanc

Next, we will upload the DICOM file into Orthanc. We could use the web GUI, but due to a longstanding Firefox issue, it suggests we use the command line. Works for me! This site suggests a number of ways; because we only have one file, we will just use curl to POST it to Orthanc. Run the following:

curl -X POST http://localhost:8042/instances --data-binary @/etc/clara/experiments/makedicom/testdicom.dcm

You should get a positive response in JSON format, along the lines of this:

A status that indicates Success is what we are looking for.

Preview the DICOM File in Orthanc

Let’s open up Orthanc in your web browser — http://localhost:8042. We can navigate the DICOM structure to check it out:

  1. You should be able to see one patient; click on that record.

2. Within that one patient, there is one study; click on that record.

3. Within that one study, there is one series; click on that record.

4. Within that one series, there is one instance; click on that record.

x

5. In this instance, you can browse the metadata of the instance — and, you can preview the image. On the bottom left hand side, click “Preview the Instance”:

And it will show you the instance:

Parting Thoughts

Congratulations! You have set up a DICOM environment on your Medical Imaging AI Workstation, and are ready to connect an end-to-end inference pipeline that includes native medical imaging files. Check out Part 12 to make this happen.

Thanks for reading. Stay safe, all.

--

--

Passionate, engaged and experienced in all things #MedicalImaging #Interoperability and #AI with #DICOM #HL7 #IHE