Main Content


Create volumetric mask from dicomContours object



BW = createMask(rtContours,roiIndex,spatial) creates the volumetric mask BW, a voxel representation of the specified ROI roiIndex from the dicomContours object rtContours. The roiIndex argument specifies which contour in rtContours to create a mask from. spatial specifies the location, resolution, and orientation of the 3-D data in world coordinates.


collapse all

Read the metadata of a DICOM-RT structure set file.

info = dicominfo("rtstruct.dcm");

Construct a dicomContours object from the metadata.

rtContours = dicomContours(info);

Display all of the ROI information as a table.

ans=2×5 table
    Number          Name           ContourData    GeometricType       Color    
    ______    _________________    ___________    _____________    ____________

      1       {'Body_Contour' }    {90×1 cell}     {90×1 cell}     {3×1 double}
      2       {'Tumor_Contour'}    {21×1 cell}     {21×1 cell}     {3×1 double}

Plot the contours of all ROIs by using the plotContours object function. This function plots the contours in world coordinates.


Create an imref3d object with the same world limits as the plotContours plot, so that the image is in the same space as the contours.

referenceInfo = imref3d([128 128 50],xlim,ylim,zlim);

Create a 3-D logical mask of the first contour, 'Body_Contour', from rtContours, with spatial referencing specified by the imref3d object.

contourIndex = 1;
rtMask = createMask(rtContours,contourIndex,referenceInfo);

View the mask using the Volume Viewer.


Input Arguments

collapse all

DICOM contours, specified as a dicomContours object.

Data Types: dicomContours

ROI in a DICOM contours object, specified as a positive integer, character vector, or string scalar. The value depends on which ROI identifier in the ROIs table of the dicomContours object you use.

ROI IdentifierTypeExample
NumberRow of the ROI in the ROIs table of the rtContours object, specified as a positive integer. Number is the first column in the ROIs table.rtMask = createMask(rtContours,1,spatialInfo)
Name Name of the ROI in the ROIs table of the rtContours object, specified as a character vector or string scalar. Name is the second column in the ROIs table.rtMask = createMask(rtContours,"Body_Contour",spatialInfo)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

Spatial referencing information, specified as a structure or an imref3d object. You can use a structure returned by dicomreadVolume that contains the fields PatientPosition, PixelSpacing, and PatientOrientation. Spatial referencing information provides the location, resolution, and orientation of the 3-D coordinate data.

Output Arguments

collapse all

Volumetric mask, returned as a 3-D logical array. The mask uses the intrinsic image coordinate system defined by spatial.

Version History

Introduced in R2020b