Skip to main content

A small library for handling masks and RT-Structs

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rt-utils-0.0.6.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rt_utils-0.0.6-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file rt-utils-0.0.6.tar.gz.

File metadata

  • Download URL: rt-utils-0.0.6.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

File hashes

Hashes for rt-utils-0.0.6.tar.gz
Algorithm Hash digest
SHA256 d187b900fdd433344f684db034e4da0fb1c772834b1e73be6571c2106765fd5e
MD5 7603990c0973bda9025695073d614dc8
BLAKE2b-256 2749b7d8c1b4d9fdd332c0a569a2f3cce48962617a50aeba8b92e126e7833f06

See more details on using hashes here.

File details

Details for the file rt_utils-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: rt_utils-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

File hashes

Hashes for rt_utils-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8bf68de29f3857c79a13b1c165442550551d7bec440acd728f6b1652671ab06a
MD5 6d72ec33aff3366173bd396cecaf8014
BLAKE2b-256 8e911cf00bf9d0da46b815f9933069cbd6aee8871360d28ee535834ccc9e6543

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page