Skip to content
forked from qurit/rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.

License

Notifications You must be signed in to change notification settings

ahxmeds/rt-utils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A minimal Python library for RTStruct manipulation

Python version PyPI version PyPI - License


RT-Utils is motivated to allow physicians and other users to view the results of segmentation performed on a series of DICOM images. RT-Utils allows you to create new RTStructs, easily add one or more regions of interest, and save the resulting RTStruct in just a few lines! Through RT-Utils, you will also be able to load 3D masks from existing RTStruct files.

How it works

RT-Utils provides a builder class to faciliate the creation and loading of an RTStruct. From there, you can add ROIs through binary masks and optionally input the colour of the region along with the region name.

The format for the ROI mask is an nd numpy array of type bool. It is an array of 2d binary masks, one plane for each slice location within the DICOM series. The slices should be sorted in ascending order within the mask. Through these masks, we extract the contours of the regions of interest and place them within the RTStruct file. Note that there is currently only support for the use of one frame of reference UID and structered set ROI sequence. Also note that holes within the ROI may be handled poorly.

Installation

pip install rt_utils

Creating new RTStructs

from rt_utils import RTStructBuilder

rtstruct = RTStructBuilder.create_new(dicom_series_path="./testlocation")
rtstruct.add_roi(
  mask=MASK_FROM_ML_MODEL, 
  color=[255, 0, 255], 
  name="RT-Utils ROI!"
)
rtstruct.save("test-rt-struct.dcm")

Loading existing RTStructs

from rt_utils import RTStructBuilder

rtstruct = RTStructBuilder.create_from(
  dicom_series_path="./testlocation", 
  rt_struct_path="./testlocation/rt-struct.dcm"
)
rtstruct.add_roi(
  mask=MASK_FROM_ML_MODEL, 
  color=[255, 0, 255], 
  name="RT-Utils ROI!"
)
rtstruct.save("updated-rt-struct.dcm")

Creation Results

The results of a generated ROI with a dummy mask, as viewed in Slicer.

Loading an existing RTStruct contour as a mask

import matplotlib.pyplot as plt
from rt_utils import RTStructBuilder

rtstruct = RTStructBuilder.create_from(
  dicom_series_path="./testlocation", 
  rt_struct_path="./testlocation/rt-struct.dcm"
)

mask_3d = rtstruct.get_roi_mask_by_name("ROI NAME")
first_mask_slice = mask_3d[:, :, 0]
plt.imshow(first_mask_slice) # View one slice within the mask
plt.show()
rtstruct.save("updated-rt-struct.dcm")

Loading Results

The results of a loading an exisiting ROI as a mask, as viewed in Python.

About

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%