Technical Articles and Newsletters

Developing matRad, an Open-Source Dose Calculation and Optimization Toolkit for Radiation Therapy Planning

By Dr. Mark Bangert, German Cancer Research Center (DKFZ), Prof. Oliver Jäkel, German Cancer Research Center (DKFZ) and University of Heidelberg, Dr. Niklas Wahl, German Cancer Research Center (DKFZ), and Dr. Hans-Peter Wieser, Ludwig-Maximilian-Universität München (LMU Munich)

Radiotherapy, surgery, and chemotherapy constitute the three pillars of cancer treatment. One key element of radiotherapy is a heavily computer-aided process known as radiation treatment planning. In this process, oncologists and other clinicians rely on treatment planning software to accurately simulate the effect of radiation on patient tissue and to optimize the radiation dose so as to ensure tumor coverage while sparing surrounding tissue and organs.

Commercially developed radiotherapy treatment planning software is proprietary and closed-source, which limits its value to researchers working to advance treatment planning technology. As a result, many institutes and universities either invest significant effort in developing and maintaining their own software or use open-source packages, most of which focus on only a single step in treatment planning or a single radiation modality.

Our development team at the German Cancer Research Center (Deutsches Krebsforschungszentrum, or DKFZ) has created matRad1, an open-source, multimodality dose calculation and optimization toolkit for radiation treatment planning (Figure 1). Because matRad is written entirely in MATLAB®, researchers can easily modify the code to evaluate new algorithms. MATLAB excels at performing the many sparse matrix operations involved in treatment planning; as a result, matRad produces clinically accurate treatment plans as quickly and easily as its commercial counterparts.

Figure 1. The matRad 2.10.0 interface, with workflow, plan, optimization, and visualization controls. The interface shows a prostate treatment plan using two opposing beam angles and scanned protons

Using matRad in a Treatment Planning Workflow

The matRad package includes MATLAB scripts, functions, and classes that span the entire treatment planning workflow, from setting treatment parameters and optimizing the plan to visualizing and evaluating the results. Researchers initiate each step in this workflow either in the matRad interface or from the MATLAB command line.

A researcher first imports computer tomography (CT) scan data from one of their own patients or from one of the anonymized patient cases provided by matRad. The software reads the data from MATLAB files or from files in the Digital Imaging and Communications in Medicine (DICOM) and DICOM-RT standard formats using functions from Image Processing Toolbox™.

Next, the researcher specifies parameters for the treatment plan and the radiotherapy machine to be used. These parameters could include the number of angles for the gantry (used to position the radiation source around the patient) and the treatment modality to be applied: intensity-modulated photons, scanned protons, or scanned carbon ions. The parameters can be set via the interface or by editing the matRad script (Figure 2).

Figure 2. A segment of the matRad script for setting the treatment plan parameters used for the plan displayed in Figure 1.

matRad generates the beam geometry based on the parameters specified. The researcher then invokes the function for matRad dose calculation, which computes a matrix of the dose delivered to individual regions of the target tumor and to surrounding normal tissue for each radiation source element (Figure 3).

Figure 3. Schematic of a proton treatment plan set-up for dose calculation. From a virtual radiation source (yellow) the tumor or target volume (red) within the patient (green) is covered by individual proton beams forming their so-called Bragg-peak at a defined range (solid black lines and dots). The matRad dose calculation function performs a volumetric raycast through the patient (solid and dashed lines) to capture anatomical heterogeneities and then computes the dose contribution in the patient for each ray.

Finally, the researcher defines clinical objectives and constraints for the treatment. These might include the prescribed minimum dose to be delivered to the tumor and the maximum dose allowed to reach a nearby organ. After translating these clinical objectives and constraints into mathematical objectives and constraints, matRad runs an optimization solver to find the best dose distribution. For the optimization, matRad can be set up to use fmincon from Optimization Toolbox™ or IPOPT, an open-source optimization software library written in C++ and imported into MATLAB as a MEX file. The results of the optimization can be reviewed in matRad in a variety of plots and visualizations (Figure 4). 

Figure 4. Visualizations generated in matRad. Left: CT and planned proton dose in the coronal plane of a head-and-neck cancer case. Center: 3D rendering of the same visualization. Right: Sample dose histograms and statistics tables.

Researchers can supplement or modify the algorithms used in matRad to explore ideas for improving treatment planning. In this way, matRad acts as a platform for prototyping and evaluating new approaches. In fact, matRad has been cited in more than 40 published peer-reviewed research papers in the past three years, and it is actively used in numerous research groups worldwide.

matRad in the Classroom

matRad is not only used in research; it is also used as a teaching tool. In a course at Heidelberg University, for example, students use matRad to learn about treatment planning for particle therapy, a relatively new modality. matRad plays an important role in letting students explore how different medical decisions, patient scenarios, and machine capabilities affect treatment planning. We packaged a standalone version of matRad with MATLAB Compiler™ for use by students who do not have MATLAB installed.

For high school students, the International Particle Physics Research Group offers a series of International Masterclasses. In a new Particle Therapy Masterclass, which we initiated in 2019 in collaboration with CERN and GSI Darmstadt, students learn about cancer treatment using radiotherapy and watch a demonstration of treatment planning using the standalone version of matRad.


Several factors led our team to develop matRad in MATLAB. First, MATLAB is widely used in the medical physics community and at research universities. In addition, MATLAB enables us to prototype new algorithms quickly. Its visualization capabilities support rapid debugging and offer perspectives on the results that open additional avenues to explore. MATLAB is well suited to the calculations that matRad performs with sparse matrices. The highly optimized linear algebra operations in MATLAB enable us to complete dose calculation and optimizations for realistic patient cases with run-times comparable to those of commercial treatment planning systems. Finally, developing matRad in MATLAB enabled us to make the software highly versatile: users can interact with the software via an interface or via the MATLAB command line, develop their own functions, and use matRad for both research and teaching.

Ongoing matRad Development

matRad remains under active development, and we regularly accept pull requests from researchers who have made improvements to some aspect of the code. For example, we recently worked with Dr. Edgardo Dörner at Pontificia Universidad Católica de Chile to incorporate a Monte Carlo photon dose calculation engine into matRad. The engine was written in C and imported into matRad as a MEX file.

In addition, we have started taking advantage of MATLAB object-oriented programming features. For example, matRad now uses an object-oriented framework for setting optimization objectives. Researchers who are interested in exploring new optimization objectives can derive their own class from our existing class, implement improvements, and then immediately try the new objective in a test treatment plan.

We are now using Parallel Computing Toolbox™ to execute matRad on multiple computing cores. For example, in uncertainty analyses we calculate multiple doses from different patient positions. Parallel Computing Toolbox enables us to rapidly set up and run this embarrassingly parallel task on a multicore workstation. We’ve also started running matRad on OpenStack to take advantage of larger pools of high-performance computing resources in the cloud.

matRad was designed as a research tool, and therefore cannot be used to treat real patients. The dose calculations it produces, however, closely match those produced by clinically approved treatment planning systems. This level of performance opens opportunities to use matRad as an independent tool for validating treatment plans generated by other software.

1 The current release is matRad ‘Blaise’ 2.10.0.

About the Authors

Dr. Mark Bangert initiated the matRad project during his time as postdoc and group leader at DKFZ. He is now working as a software engineer at HMS Analytical Software, a Heidelberg data analytics company, while still holding a part-time position in the Department of Medical Physics at the German Cancer Research Center (DKFZ) in Heidelberg.

Prof. Oliver Jäkel is a full professor of Medical Physics at the Medical Faculty at the University of Heidelberg and the Medical Physics Director of the Heidelberg Ion-beam Therapy Facility (HIT). He also heads the Department of Medical Physics in Radiation Oncology at DKFZ.

Dr. Niklas Wahl is currently leading the matRad development as postdoctoral researcher and leader of the Radiotherapy Optimization group in the Department of Medical Physics in Radiation Oncology at DKFZ.

Dr. Hans-Peter Wieser is a postdoctoral researcher in the Department of Medical Physics at Ludwig-Maximilian-University München. Previously, he did his Ph.D. in the Department of Medical Physics in Radiation Oncology at DKFZ, where he made major contributions to matRad.

Published 2020

View Articles for Related Industries