Clara Segmentation Contour Detection Operator

This application is NOT for medical use.

This application calculates the contours of a segmentation mask image in MetaImage format and saves the contour points as a nested list in a JSON file. It supports a single label mask in the segmentation image.

This application, in the form of a Docker container, expects an input folder (/input by default), which must be mapped to a host folder. The following file is expected in the folder:

  • An image file in MetaImage format containing the segmentation mask with a single label

This application saves a nested list in JSON format to the output folder (/output by default). The output filename is the same as the input filename, but with the .json extension. The /output folder must be mapped to a host folder.

The following is the schema of the nested list:

  • A list of items, with each item containing a list of contours for the corresponding slice in the segmentation image. If there is no contour points on a slice, the item is still present but empty.
  • A list of contours on a specific slice. The list is zero length if there are no contour points.
  • A list of points for each contour, with each point being a list of three floats representing 3D coordinates in the coordinate system defined in the segmentation image.

The following is a condensed example with 5 slices in the image:


[ [], [ [ [ -21.628832700592994, 8.208444049987097, -34.900416875535804 ], [ -21.628832700449735, 8.758731224603924, -35.139548751417 ] ] ], [ [ [ -21.637283139498905, 3.3509285999774914, -29.518566976497958 ], [ -22.237280782818715, 3.9005421788187995, -29.75924892261019 ], [ -22.837278426281785, 3.899868583043281, -29.76079899284123 ] ] ], [], [] ]

Logs generated by the application are saved in a folder (/logs by default), which must be mapped to a host folder.

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


/app_contour_detection ├── ├── contour_detection │   ├── │   ├── │   ├── │   └── ├── Dockerfile ├── ├── logging_config.json ├── ├── ngc │   ├── metadata.json │   └── ├── public │   └── docs │   └── ├── requirements.txt ├── └── test-data └── 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

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 the Docker terminal, ensure the current directory is app_contour_detection.
  3. Copy test-data/input/mhd/* to /input.
  4. Create /output and /logs folders.
  5. Enter the command python ./".
  6. Once finished, type exit.


  • The segmentation mask image file in MetaImage format
  • The original dcm files from the single DICOM series used for 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.
  • output for the generated DICOM RTSTRUCT dcm file.
  • logs for log files.

Step 3

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


SCRIPT_DIR=$(dirname "$(readlink -f "$0")") TESTDATA_DIR=$(readlink -f "${SCRIPT_DIR}"/test-data) APP_NAME="app_contour_detection" INPUT_TYPE="mhd" # Build Dockerfile 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 \ -e DEBUG_VSCODE \ -e DEBUG_VSCODE_PORT \ -e NVIDIA_CLARA_NOSYNCLOCK=TRUE \ ${APP_NAME} echo "${APP_NAME}has finished."

Step 4

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


Step 5

Check for the following output files:

  • A contour file in the output directory with the same filename as the input file, but with the .json extension.
© Copyright 2018-2020, NVIDIA Corporation. All rights reserved. Last updated on Feb 1, 2023.