Main Content

Add and Modify ROIs of DICOM-RT Contour Data

This example shows how to extract and modify contour data stored in a DICOM-RT structure set.

A DICOM-RT structure set is a DICOM Information Object Definition (IOD) specific to radiotherapy. The metadata of a DICOM-RT structure set file includes contour data for regions of interest (ROIs) relevant to radiation treatment planning. This example extracts ROI contour data into a dicomContours object, and uses object functions to display, add, and remove ROIs and save the modified contours to a new metadata structure. These steps are useful for exploring DICOM-RT structure files and for writing new metadata structures if you update the contour data in MATLAB®. This example uses a data set defining contours for a human torso and synthetic tumor and organ regions.

Read the DICOM metadata from a DICOM-RT structure set file by using the dicominfo function.

info = dicominfo("RTSTRUCT-VS-SEG-001.dcm");

Extract the ROI data from the DICOM metadata. The output is a dicomContours object that stores the extracted ROI data.

contourData = dicomContours(info);

Display the ROIs property of the dicomContours object. The ROIs property is a table that contains the extracted ROI data.

contourData.ROIs
ans=4×5 table
    Number       Name        ContourData    GeometricType       Color    
    ______    ___________    ___________    _____________    ____________

      1       {'TV'     }    {13x1 cell}     {13x1 cell}     {3x1 double}
      2       {'Cochlea'}    { 5x1 cell}     { 5x1 cell}     {3x1 double}
      3       {'Vol2016'}    {12x1 cell}     {12x1 cell}     {3x1 double}
      4       {'*Skull' }    {79x1 cell}     {79x1 cell}     {3x1 double}

Plot the ROI contour data from the dicomContours object.

figure
plotContour(contourData)
axis equal

Figure contains an axes object. The axes object contains 109 objects of type line.

Load the MAT file countours.mat into the workspace. The cell array contours specifies 3-D coordinates of the boundary points for a new ROI with 21 axial slices.

load("contours.mat")

To create an ROI sequence that contains the new ROI contour data, specify these attributes.

  • ROI number

  • User-defined name for the ROI

  • Geometric type of the contours

The ROI number for the sequence must be unique, but the ROI name can be any user-defined name. Because all points in the new ROI contour data are coplanar, and the last point is connected to the first point, specify the geometric type as "Closed_planar". Specify the display color for plotting the new ROI as blue-green.

number = 5;
name = "Organ";
geometricType = "Closed_planar";
color = [0; 127; 127];

Add the new ROI sequence to the ROIs property of the dicomContours object. The output is a dicomContours object that contains the new ROI sequence, as well as the original ones.

contourData = addContour(contourData,number,name,contours,geometricType,color);
contourData.ROIs
ans=5×5 table
    Number       Name        ContourData    GeometricType       Color    
    ______    ___________    ___________    _____________    ____________

      1       {'TV'     }    {13x1 cell}     {13x1 cell}     {3x1 double}
      2       {'Cochlea'}    { 5x1 cell}     { 5x1 cell}     {3x1 double}
      3       {'Vol2016'}    {12x1 cell}     {12x1 cell}     {3x1 double}
      4       {'*Skull' }    {79x1 cell}     {79x1 cell}     {3x1 double}
      5       {'Organ'  }    {21x1 cell}     {21x1 cell}     {3x1 double}

Plot the updated contour data.

figure
plotContour(contourData)
axis equal

Figure contains an axes object. The axes object contains 130 objects of type line.

Delete the tumor ROI specified by ROI number 2.

contourData = deleteContour(contourData,2);
contourData.ROIs
ans=4×5 table
    Number       Name        ContourData    GeometricType       Color    
    ______    ___________    ___________    _____________    ____________

      1       {'TV'     }    {13x1 cell}     {13x1 cell}     {3x1 double}
      3       {'Vol2016'}    {12x1 cell}     {12x1 cell}     {3x1 double}
      4       {'*Skull' }    {79x1 cell}     {79x1 cell}     {3x1 double}
      5       {'Organ'  }    {21x1 cell}     {21x1 cell}     {3x1 double}

Plot the final contour data.

figure
plotContour(contourData)
axis equal

Figure contains an axes object. The axes object contains 125 objects of type line.

Export the modified ROI data to a DICOM metadata structure.

info = convertToInfo(contourData);

Write the metadata to a DICOM-RT structure set file by using the dicomwrite function. If the DICOM image associated with the ROI contour data is not available, specify the first input argument value in the dicomwrite function as an empty array. Set the CreateMode name-value argument to "copy" to copy the metadata to a new DICOM-RT structure set file, rtfile.dcm.

dicomwrite([],"rtfile.dcm",info,CreateMode="copy");

Verify that the new file includes the correct ROI contour data.

info_test = dicominfo("rtfile.dcm");
contour_test = dicomContours(info_test);
contour_test.ROIs
ans=4×5 table
    Number       Name        ContourData    GeometricType       Color    
    ______    ___________    ___________    _____________    ____________

      1       {'TV'     }    {13x1 cell}     {13x1 cell}     {3x1 double}
      3       {'Vol2016'}    {12x1 cell}     {12x1 cell}     {3x1 double}
      4       {'*Skull' }    {79x1 cell}     {79x1 cell}     {3x1 double}
      5       {'Organ'  }    {21x1 cell}     {21x1 cell}     {3x1 double}

See Also

| | | | |

Related Topics