10.21. DICOM RTSTRUCT Writer Operator

This application is NOT for medical use.

This asset requires the Clara Deploy SDK. Follow the instructions on the Clara Ansible page to install the Clara Deploy SDK.

10.21.1. Overview

This example application creates a DICOM RT Structure Set, of modality type RTSTRUCT, from a segmentation mask image in MetaImage format, and optionally from the original DICOM series. It can also directly consume a text file containing the detected contours instead of the segmentation mask image. If the corresponding DICOM Part 10 files for the series are provided, the referenced SOP instance UIDs (and other attributes) will be set accordingly in the RTSTRUCT. The output is a DICOM instance of modality type RTSTRUCT stored in a DICOM Part 10 file.

New functionalities introduced in Release 0.7.4 include algorithms to generate the surface mesh of the segmentation image, and to encode the mesh in binary form compatible with stl file format. Additionally, the binary stl data is included in a private tag in the DICOM RT Structure Set: Tag (0011, 1001) has the VR of OB and its value the binary data of the stl file, while (0011,0010) is for the Private Creator Data Element.

10.21.2. Inputs

This application, in the form of a Docker container, expects the following inputs:

  • in the /input folder, by default, one of the following two types of files must be present:
    1. An image file in MetaImage format, which is the segmentation mask with a single label, in MetaImage or NIfTI format
    2. A JSON file that contains the nested list of contours
  • In the /dcm folder, by default, the original DICOM instance files of the DICOM series that are used to generate the segmentation mask. The instance files can be in a subfolder under /dcm, but all instances of a single series must be within the same folder. If DICOM series is absent or missing some instances, the DICOM RT Dataset can still be created, but the attributes referring to original SOP instances will be absent or have empty values
  • in the folder /series_selection, by default, the selected series image file, selected-images.json, output of DICOM Parser or Series Selection operator, whichever is used to select the series and its image for inference

10.21.3. Outputs

  • This application saves the DICOM RTSTRUCT to the output folder (/output by default) in DICOM File Format. The file name is generated by suffixing the input file name with -RTSTRUCT and the extension dcm. The output folder must be mapped to a host folder.
  • Introduced in Release 0.7.4 is a DICOM private tag whose value is the binary content of the stl file for the surface mesh of the segmentation image: Tag (0011, 1001) has the VR of OB and its value the binary data of the stl file, while (0011,0010) is for the Private Creator Data Element.
  • Logs generated by the application are saved in a folder (/logs by default), which similarly must be mapped to a host folder.

10.21.4. Environment Variables

The application supports the following environment variables:

  • NVIDIA_CLARA_INPUT: The root folder where the application searches for AI result file, default /input
  • NVIDIA_CLARA_OUTPUT: The folder where the application saves generated DICOM instance files, default /output
  • NVIDIA_CLARA_LOGS: The folder for application logs, default /logs
  • NVIDIA_CLARA_DCM: The folder where the application searches for the original DICOM study instance files, default /dcm
  • 'NVIDIA_CLARA_SERIES_SELECTION: The folder where the application searches for selected series JSON file, default /series_selection

10.21.5. Directory Structure

The directories in the container are shown below. The core of the application code is under the folder rtstruct_writer.

├── buildContainers.sh
├── Dockerfile
├── __init__.py
├── logging_config.json
├── main.py
├── ngc
│   ├── metadata.json
│   └── overview.md
├── public
│   └── docs
│       └── README.md
├── requirements.txt
├── rtstruct_writer
│   ├── app.py
│   ├── contour_detector.py
│   ├── dicom_parser.py
│   ├── __init__.py
│   ├── rtstruct_writer.py
│   └── runtime_envs.py
├── run_app_docker.sh
└── test-data
    ├── dcm
    │   ├── IMG0001.dcm
    │   ├── IMG0002.dcm
    │   ├── IMG0003.dcm
    │   ├── IMG0004.dcm
    │   ├── IMG0005.dcm
    │   ├── IMG0006.dcm
    │   ├── IMG0007.dcm
    │   ├── IMG0008.dcm
    │   ├── IMG0009.dcm
    │   ├── IMG0010.dcm
    │   ├── IMG0011.dcm
    │   ├── IMG0012.dcm
    │   ├── IMG0013.dcm
    │   ├── IMG0014.dcm
    │   ├── IMG0015.dcm
    │   ├── IMG0016.dcm
    │   ├── IMG0017.dcm
    │   ├── IMG0018.dcm
    │   └── IMG0019.dcm
    ├── json
    │   └── 1.2.826.0.1.3680043.2.1125.1.48532560258338587890405155270906492.output.json
    └── mhd
        ├── 1.2.826.0.1.3680043.2.1125.1.48532560258338587890405155270906492.output.mhd
        └── 1.2.826.0.1.3680043.2.1125.1.48532560258338587890405155270906492.output.raw

10.21.6. Executing the Operator Locally

If you want to see the internals of the container and manually run the application, follow these steps:

  1. Start the container in interactive mode. See the next section on how to run the container, and replace the docker run command with docker run --entrypoint /bin/bash.
  2. Once in the Docker terminal, ensure the current directory is /app_rtstruct_writer.
  3. Copy test-data/input/mhd/* to /input, test-data/dcm/* to /dcm, and test-data/series_selection/* to /series_selection
  4. Create /output and /logsfolders.
  5. Enter the command python ./main.py".
  6. Once finished, type exit.

10.21.7. Executing Operator in Docker Prerequisites

  • The segmentation mask image file in MetaImage format
  • The original dcm files from the single DICOM series used for the segmentation Step 1

Change to your working directory (e.g. my_test). Step 2

Create, if they do not exist, the following directories under your working directory:

  • input and copy over the segmentation mask image file.
  • dcm and copy over the dcm files of the original DICOM series.
  • output for the generated DICOM RTSTRUCT dcm file.
  • logs for log files. Step 3

In your working directory, create a shell script (e.g. run_app_docker.sh or other name if you prefer), copy the sample content below, save it, and make sure the variable TAG has the same value as the actual container tag:

SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
TESTDATA_DIR=$(readlink -f "${SCRIPT_DIR}"/test-data)
INPUT_TYPE="mhd"   # Change to json if using detected contours

# Build Docker image
docker build -t ${APP_NAME} -f ${SCRIPT_DIR}/Dockerfile ${SCRIPT_DIR}

# Run ${APP_NAME} container.
docker run --name ${APP_NAME} -t --rm \
    -v ${TESTDATA_DIR}/${INPUT_TYPE}:/input \
    -v ${SCRIPT_DIR}/output:/output \
    -v ${SCRIPT_DIR}/logs:/logs \
    -v ${TESTDATA_DIR}/dcm:/dcm \

echo "${APP_NAME} has finished." Step 4

Execute the script below and wait for the application container to finish:

./run_app_docker.sh Step 5

Check for the following output files:

  • The segmentation results in the output directory
  • A file with the same name as the input file, suffixed with -RTSTRUCT and the extension .dcm. Step 6

To visualize the results, use 3D Slicer with RT Extension or a DICOM viewer that supports RTSTRUCT. For detailed steps, see the viewer documentation. The key steps are as follows:

  1. Import the DICOM RTSTRUCT dcm file as well as the original DICOM series.
  2. Load both the original and the RTSTRUCT series.
  3. Scroll through the slices.
  4. To view 3D rendering, select the Volume Rendering module and enable the loaded volume.

10.21.8. License

An End User License Agreement is included with the product. By pulling and using the Clara Deploy asset on NGC, you accept the terms and conditions of these licenses.

10.21.9. Suggested Reading

Release Notes, the Getting Started Guide, and the SDK itself are available at the NVIDIA Developer forum.

For answers to any questions you may have about this release, visit the NVIDIA Devtalk forum.