New piece Team Members

Generating RT Structs in Python with RT-UTILS

Seventh post in a series of posts written by members of the Qurit Team. Written by Asim Shrestha.

Introducing RT-UTILS

DICOM and RT Structures are the primary means in which medical images are stored. Because of this, it is important to be able to translate data in and out of RT Structs. Although there are well documented mechanisms for loading RT Structures within Python, we found that creating such files ourselves proved difficult. Existing tools felt complicated and clunky and so we set out to make our own library. Introducing RT-Utils, a lightweight and minimal python package for RT Struct manipulation.

What kind of manipulation is possible?

When we say manipulation, we mean that users are able to both load in existing RT Struct files or create new RT Structs given a DICOM series. After doing so, they can perform the following operations:

  • Create a new ROI within the RT Struct from a binary mask. Optionally, one can also specify the color, name, and description of the RT Struct.
  • List the names of all the ROIs within the RT Struct.
  • Load ROI mask from the RT Struct by name.
  • Save the RT Struct by name or path.

How are DICOM headers dealt with?

Our approach with headers are simple. We first add all of the headers required to make the RT Struct file a valid RT Struct. After this, we transfer all of the headers we can from the input DICOM series such as patient name, patient age, etc. Finally, as users input ROIs within the RT Struct, they will be dynamically added to the correct sequences within the RT Struct.


pip install rt-utils

After installation, you then import RTStructBuilder and either create a new RT Struct or load an existing RT Struct. Below are examples of both of these. Pay attention to the comments in the code snippets to get a better idea of what is going on.

Adding a ROI mask

The ROI mask format required for the add_roi method is a 3D array where each 2D slice of the array is a binary mask. Values of one within the mask indicate that the pixel is a part of the ROI, for a given slice. There must be as many slices within the array as there are slices within your DICOM series. The first slice in the array corresponds to the smallest slice location in the DICOM series, the second slice corresponds to the second slice location, etc.

Creating new RT Structs

from rt_utils import RTStructBuilder
rtstruct = RTStructBuilder.create_new(dicom_series_path="./testlocation")
# …
# Create mask through means such as ML
# …
# Add the 3D mask as an ROI.
# The colour, description, and name will be auto generated
# Add another ROI, this time setting the color, description, and name
color=[255, 0, 255],
name="RT-Utils ROI!"
view raw hosted with ❤ by GitHub
Resulting RT Struct ROI as viewed in Slicer

Loading and viewing existing RT Structs

from rt_utils import RTStructBuilder
import matplotlib.pyplot as plt
# Load existing RT Struct. Requires the series path and existing RT Struct path
rtstruct = RTStructBuilder.create_from(
# View all of the ROI names from within the image
# Loading the 3D Mask from within the RT Struct
mask_3d = rtstruct.get_roi_mask_by_name("ROI NAME")
# Display one slice of the region
first_mask_slice = mask_3d[:, :, 0]
view raw hosted with ❤ by GitHub
Result of viewing a mask slice within an existing RT Struct

Bonus: Dealing with holes in masks and ROI’s

Often times, DICOM viewing tools such as MIM will automatically detect inner and outer contours and draw holes accordingly. This is not always the case however and sometimes you will be required to create pin holes within your ROI so that your ROIs are displayed properly. This process is described in this link.

An ROI in slicer not properly displaying the hole within the region

If this is the situation you are under, we have another optional parameter that can deal with this for you. When you are adding ROIs to your RT Struct, simply set use_pin_hole=True like as the example below.

rtstruct.add_roi(mask, use_pin_hole=True)
view raw hosted with ❤ by GitHub
The same region as before, but now with a pin hole carved out. In doing this, the inner hole now displays properly.
Interesting links/news New piece Team Members

Using radioactive epoxy lesions in phantoms

Presentation by our fantastic co-op student, Roberto Fedrigo, to the UBC Multidisciplinary Undergraduate Research Conference (MURC), with title, “Phantom-guided optimization of prostate cancer PET imaging using radioactive epoxy lesions”:

New piece New publication

Featured News Article on Cardiac PET Imaging

Our recent publication on the impact of respiratory motion correction for ejection fraction (EF) measurements in cardiac PET has now been features as a news article on medicalphysicsweb. The findings of this work reiterate the significant potential of respiratory motion correction for this important clinical imaging task.

Interesting links/news New piece

Publication in the top 10 most popular PMB articles in 2016

Our article on dynamic whole-body imaging has been ranked among top 10 most popular articles in the journal of Physics in Medicine & Biology (PMB) in 2016. The work was also featured on medicalphysicsweb in a piece titled “A clinical take on whole-body dynamic PET“. The work is creating excitement in its potential to transform routine clinical imaging, to enable dynamic PET imaging while still providing conventional whole-body standard uptake value (SUV) images.

Interesting links/news New piece

Siemens pushing forward with whole-body dynamic PET imaging

This is a good piece (Siemens) outlining a new direction in PET imaging: Think Whole-body Dynamic PET Imagings for Research Only? Perhaps it’s Time to Re-evaluate. Also see an example dynamic imaging animation. Our group was the earliest one to propose (in 2011) and extensively publish this promising approach (e.g. companion papers in 2013, and onwards). It is very rewarding to see that this framework may be translated to clinical practice, thanks to efforts of multiple groups that are now pursuing it.


Interesting links/news New piece New publication

A race effect on amyloid deposition?

Our recent publication in the journal Neurology has been accompanied by a nice editorial reviewing and discussing the novel finding. This work involved recruitment of subjects from the longitudinal Atherosclerosis Risk in Communities (ARIC) study, for  an additional PET scan to visualize amyloid in the brain, which has been a major breakthrough in the field of Alzheimer disease (AD). The resulting ARIC-PET amyloid imaging study revealed for the first time that black subjects depicted higher amyloid levels, even after adjustment for demographics, vascular risk factors, and cognitive status, making the provocative suggestion that there might be race differences in the process of amyloid deposition.

The analysis itself was stimulated by reports of increased prevalence of AD in black compared to white individuals. In this major NIH funded effort (PI: Gottesman), extensive site travel, quality assurance and quantitative analysis was performed by Chief Physicist Dr. Rahmim for data obtained from the three PET imaging sites (Washington County, MD; Jackson, MS; and Forsyth County, NC).


New piece

Point/counterpoint on resolution modeling in PET

The following point/counterpoint was just published in Med. Phys. It was a fun and interesting piece to write, and both Adam and I seem to have converged towards the end on a need for careful assessment of this issue within a task-based framework. It’s a short piece with lots of concise observations:

A. M. Alessio, A. Rahmim, and C. G. Orton (Moderator)
Resolution modeling enhances PET imaging
Med. Phys., vol. 40, pp. 120601, 2013.

New piece


Here we hope you will find useful information about the various things that go on in our lab.