dicom

DICOM import and export functionality for reading and writing patient data in DICOM format.

matRad_convRtssContours2Indices(structure, ct)

matRad function to convert a polygon segmentation from an rt structure set into a binary segmentation as required within matRad’s cst struct

call

indices = matRad_convRtssContours2Indices(contPoints,ct)

Input:
  • structure – information about a single structure

  • ct – matRad ct struct where the binary segmentations will be aligned to

Output:

indicies – indices of voxels of the ct cube that are inside the contour

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_interpDicomCtCube(origCt, origCtInfo, resolution, doseGrid)

matRad function to interpolate a 3D ct cube to a different resolution

call

interpCt = matRad_interpDicomCtCube(origCt, origCtInfo, resolution) interpCt = matRad_interpDicomCtCube(origCt, origCtInfo, resolution, doseGrid)

Input:
  • origCt – original CT as matlab 3D array

  • origCtInfo – meta information about the geometry of the orgiCt cube

  • resolution – target resolution [mm] in x, y, an z direction for the new cube

  • doseGrid – optional: externally specified grid vector

Output:

interpCt – interpolated ct cube as matlab 3D array

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importFieldShapes(beamSequence, fractionSequence)

function to import collimator shapes from a DICOM RT plan

call

collimation = matRad_importFieldShapes(beamSequence, fractionSequence)

Input:
  • beamSequence – struct containing the beamSequence elements from the RT plan

  • fractionSequence – struct containing the fractionGroupSequence elements from the RT plan

Output:
  • collimation – struct with all meta information about the collimators and

  • all field shape matrices

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_calcWaterEqD(ct, radiationMode)

matRad function to calculate the equivalent densities from a dicom ct that originally uses intensity values

call

ct = matRad_calcWaterEqD(ct, radiationMode)

Input:
  • ct – ct containing a cubeHU to compute rED/rSP values from

  • radiationMode – radiationMode as character array (e.g. ‘photons’) since matRad 3. Can also be a pln-struct for downwards compatibility

Output:
  • ct – ct struct with cube with relative _electron_ densities stored in

  • ct.cube

References

Copyright 2018-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_loadHLUT(ct, radiationMode)

matRad function to load HLUT file based on the provided ct

call

hlut = matRad_loadHLUT(ct, pln)

Input:
  • ct – ct with dicom information

  • radiationMode – radiationMode as character array (e.g. ‘photons’) since matRad 3. Can also be a pln-struct for downwards compatibility

Output:

hlut – lookup table

References

Copyright 2018-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomGUI()

matRad compatability function to call the dicom importwidget

call

matRad_importDicomGUI

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_checkEnvDicomRequirements(env)

matRad function to check if requirements for dicom import / export are given. Throws an error if requirements not met

call

matRad_checkEnvDicomRequirements(env)

Input:

env – folder to be scanned

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_listAllFiles(dirPath, uiInput)

matRad function to get all files in arbitrary deep subfolders

call

fileList = matRad_listAllFiles() fileList = matRad_listAllFiles(dirPath) fileList = matRad_listAllFiles(uiInput)

Input:
  • dirPath – (optional) initial folder to start searching

  • uiInput – (optional) if userInteraction is wanted. Use EITHER dirPath or uiInput

Output:

fileList – Filelist

References
Note

MATLAB has an internal recursion limit. If you want to list a huge amount of files you may have to: >> % N = Number of allowed recursions >> set(0,’RecursionLimit’,N)


Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_exportDicomGUI()

matRad compatability function to call the dicom export widget

call

matRad_importDicomGUI

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


DICOM Exporter

Class handling the export of matRad treatment plan data to DICOM format.

class matRad_DicomExporter(ct, cst, pln, stf, resultGUI)

Bases: handle

matRad_DicomExporter matRad class to handle a dicom export.

Example on how to use the matRad_DicomExport class

dcmExpObj = matRad_DicomExporter; % create instance of matRad_DicomExporter dcmExpObj.dicomDir = ‘pathAsString’; % set the output path for the Dicom export dcmExp.matRad_exportDicom(); % run the export

References

Copyright 2020-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_DicomExporter Construct an instance of this class Can be called with the structures. If no argument is given, all structures will be read from the base workspace

Property Summary
dicomDir = ['.'filesep]

output folder

exportScenario = 1

which scenario to export (no 4D data supported for now)

ct = []

matRad structures to export

cst = []
stf = []
pln = []
resultGUI = []
PatientID

Study & Patient Dicom Information

PatientName
PatientPosition
PatientBirthDate = ''
PatientSex = ''
StudyID
StudyDate
StudyTime
StudyInstanceUID
FrameOfReferenceUID
OperatorsName

Operator

ctFilePrefix = 'ct_slice_'

ct

ctMeta
ctSliceMetas
ctExportStatus
rtssFileName = 'RTStruct'

rtstruct

rtssMeta
rtssExportStatus
rtDoseFilePrefix = 'RTDose_'

RTdose

rtDoseNames
rtDoseMetas
rtDoseExportStatus
rtPlanFilePrefix = 'RTPlan'

RTPlan

rtPlanMeta
rtPlanExportStatus
rtPlanLabel = 'matRadPlan'
rtPlanName = 'matRadPlan'
externalContourDict = {'EXTERNAL','BODY','PATIENT'}

some dictionaries

targetPtvDict = {'PTV','MARGIN'}
targetCtvDict = {'CTV'}
targetGtvDict = {'GTV','TUMOR'}
enableRtPlanExport = false

enable RTPlan Export

rtPlanClassUID = '1.2.840.10008.5.1.4.1.1.481.5'
rtStructClassUID = '1.2.840.10008.5.1.4.1.1.481.3'
rtDoseClassUID = '1.2.840.10008.5.1.4.1.1.481.2'
ctClassUID = '1.2.840.10008.5.1.4.1.1.2'
Method Summary
generateDefaultDicomData()

generateDefaultDicomData Fill Patient & Study dicom info

static addStruct2StructArray(sarray, s, i)
addStruct2StructArray Helper function to assign structs

When assigning structs to a struct array, there is usually an error. This method works around this error by assigning a struct s to the structure array sarray field by field at position i.

call

sarray = matRad_DicomExporter.matRad_exportDicomRTStruct(sarray,s,i)

Input:
  • sarray – structure array to add struct s to

  • s – struct to add to sarray

  • i – optional index. if not given, s is appended

static assignDefaultMetaValue(meta, fn, default, displayBool)
assignDefaultMetaValue Helper function to default meta values

When meta information is already given, it may not be overwritten by a default value. This function automatically checks for a value and optionally prints to console

call

meta = matRad_DicomExporter.assignDefaultMetaValue(meta,fn,default,displayBool)

Input:
  • meta – structure with dicom meta information

  • fn – meta fieldname

  • default – default value to assign

  • displayBool – optional request for console output.

Output:

meta – meta struct with default value or value that was already there before

static dicomName(family, given, middle, prefix, suffix)
matRad_exportDicomRTPlan()

matRad function to export pln to dicom.

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_exportDicom()

matRad function to export current workspace to DICOM. Function of matRad_DicomExporter

call

matRad_DicomExporter.matRad_exportDicom()

References

Copyright 2019-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_exportDicomCt()

matRad function to export ct to dicom. Class method of matRad_DicomExporter

call

matRad_DicomExporter.matRad_exportDicomCt()

References

Copyright 2019-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_exportDicomRTStruct()

matRad function to export dicom RT structure set. Class method of matRad_DicomExporter

call

matRad_DicomExporter.matRad_exportDicomRTStruct()

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_exportDicomRTDoses()

matRad function to exportt resultGUI to dicom RT dose. Function of matRad_DicomExporter

call

matRad_DicomExporter.matRad_exportDicomRTDoses()

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


DICOM Importer

Class handling the import of patient data from DICOM files into matRad.

class matRad_DicomImporter(pathToFolder)

Bases: handle

matRad_DicomImporter matRad class to handle a dicom import.

Example on how to use the matRad_DicomImport class

dcmImpObj = matRad_DicomImporter(‘pathToFolder’); % create instance of matRad_DicomImporter dcmImpObj.matRad_importDicom(dcmImpObj); % run the import


Copyright 2020-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_DicomImporter Construct an instance of this class Can be called with the structures. If no argument is given, all structures will be read from the base workspace

Property Summary
patDir

path to DICOM file

allfiles

lists of all files

patients
selectedPatient
importFiles

all the names (directories) of files, that will be imported

importCT

properties with data for import functions

importRtss
importRTDose
ct = []

structures for .mat file

cst = []
stf = []
pln = []
resultGUI = []
ImportGrid
dicomMetaBool

bools

visBool
Method Summary
matRad_scanDicomImportFolder()

matRad function to scan a folder for dicom data

In your object, there must be a property that contains path to the folder to be scanned

Output:

- matlab struct with a list of dicom files including meta

infomation (type, series number etc.)
  • list of patients with dicom data in the folder

call

obj = matRad_scanDicomImportFolder(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomRTPlan()

matRad function to import dicom RTPLAN data

In your object, there must be properties that contain:

  • ct imported by the matRad_importDicomCt function;

  • list of RTPlan Dicom files;

  • a boolean, if you don’t want to import whole dicom information set it false.

Output - matRad pln structure with meta information. Note that bixelWidth is determined via the importSteering function.

call

obj = matRad_importDicomRTPlan(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomRtss()

matRad function to read the data of the selected dicomRT structure set file into a matRad structure

In your object, there must be properties that contain:
  • name of the rtss file;

  • meta information from the dicom ct files for sanity checks.

Optional:
  • boolean to turn on/off visualization.

Output - structure containing names, numbers, colors and coordinates of the polygon segmentations.

call

obj = matRad_importDicomRtss(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomRTDose()

matRad function to import dicom RTDOSE data

In your object, there must be properties that contain:
  • ct imported by the matRad_importDicomCt function;

  • cell array of RTDose DICOM files.

Optional:
  • matRad pln structure.

Output - matRad resultGUI structure with different beams. Note that the summation (called plan) of the beams is named without subscripts, e.g. physical_Dose.

call

obj = matRad_importDicomRTDose(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_calcHU()

matRad function to calculate Hounsfield units from a dicom ct that originally uses intensity values

In your object, there must be a property that contains unprocessed dicom ct data which are stored as intensity values (IV)

Output - ct structure with cube with HU

HU = IV * slope + intercept

call

obj = matRad_calcHU(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomSteeringParticles()

matRad function to import a matRad stf struct from dicom RTPLAN data

In your object, there must be properties that contain:
  • ct imported by the matRad_importDicomCt function;

  • matRad pln structure with meta information;

  • name of RTPLAN DICOM file.

Output - matRad stf and pln structures. Note: pln is input and output since pln.bixelWidth is determined here.

call

obj = matRad_importDicomSteeringParticles(obj)

References

Note not implemented - compensator. Fixed SAD.


Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicom()

matRad wrapper function to import a predefined set of dicom files files into matRad’s native data formats

In your object, there must be properties that contain:

  • list of files to be imported.

Optional:

  • a boolean; if you don’t want to import complete DICOM information, set it to false.

Next matRad structures are created in the object and saved in the workspace:

  • ct, cst, stf, pln, resultGUI.

To save them as .mat file you can use matRad_importDicomWidget

call

matRad_importDicom(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_interpDicomDoseCube()

matRad function to interpolate a given Dicom Dose Cube dicom RTDOSE data

In your object, there must be properties that contain:
  • ct imported by the matRad_importDicomCt function;

  • one (of several) dose cubes which should be interpolated.

Optional:
  • pln structure.

Output - structure with different actual current dose cube and several meta data.

call

obj = matRad_interpDicomDoseCube(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_createCst()

matRad function to create a cst struct upon dicom import

In your object, there must be a property that contains matlab structure containing information about rt structure set (generated with matRad_importDicomRtss and matRad_convRtssContours2Indices)

Output - matRad cst structure

call

obj = matRad_createCst(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomCt()

matRad function to import dicom ct data

In your object, there must be properties that contain:

  • list of dicom ct files;

  • resolution of the imported ct cube, i.e. this function will interpolate to a different resolution if desired;

  • a boolean, if you don’t want to import complete dicom information set it false.

Optional:

  • a priori grid specified for interpolation;

  • a boolean to turn off/on visualization.

Output - matRad ct structure. Note that this 3D matlab array contains water euqivalent electron denisities. Hounsfield units are converted using a standard lookup table in matRad_calcWaterEqD

call

matRad_importDicomCt(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_importDicomSteeringPhotons()

matRad function to import a matRad stf struct from dicom RTPLAN data

In your object, there must be a property that contains matRad pln structure with meta information (collimation data included)

Output - matRad stf and pln structures.

call

obj = matRad_importDicomSteeringPhotons(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.


matRad_dummyCst()

matRad function to create a dummy cst struct for a ct

In your object, there should be properties that contain:
  • ct structure;

  • cst structure.

Output - matRad cst structure

call

obj = matRad_dummyCst(obj)

References

Copyright 2015-2026 the matRad development team.

This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSE.md. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.