9.33. Clara Deploy DICOM Segmentation Writer Operator
CAUTION: Investigational device, not for diagnostic use. Limited by Federal (or United States) law to investigational use.
This research use only software has not been cleared or approved by FDA or any regulatory agency.
This asset requires the Clara Deploy SDK. Follow the instructions on the Clara Bootstrap page to install the Clara Deploy SDK.
This application, in the form of a Docker container, expects an input folder, /input
by default, and a DICOM file folder, /dcm
by default. Both need to be mapped to the host folders when the Docker container is started.
In the /input
folder, there must be a segmentation image file in MetaImage or NIfTI format, while the /dcm
folder contains 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 they must all be within the same folder.
The labels for the segments are provided as a stringfied array of strings in the well-known environment variable, NVIDIA_SEG_LABELS
. It is further assumed that the pixel value for the segments starts at 1 and increment sequentially. For example, in a lung and tumor segmentation, the pixel value for lung
is 1
, and tumor
2
. The array assigned to the NVIDIA_SEG_LABELS
is then '["lung", "tumor"]'
. If the environment variable is not set or is blank, the application will assume a default segmentation label default-label
for pixel value 1
.
This application saves the DICOM Segmentation object to the output folder /output
by default in DICOM Part 10 File Format. The file name is generated by suffixing the input file name with -DICOMSEG
and the extension dcm
. The output folder must be mapped to a host folder.
Logs generated by the application are saved in the folder /logs
by default, which similarly 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 dicomseg
.
/app_dicomseg_writer
├── buildContainers.sh
├── dicomseg
│ ├── app.py
│ ├── dicomseg_writer.py
│ ├── __init__.py
│ ├── runtime_envs.py
│ └── series_instance_parser.py
├── Dockerfile
├── __init__.py
├── logging_config.json
├── main.py
├── ngc
│ ├── metadata.json
│ └── overview.md
├── public
│ └── docs
│ └── README.md
├── requirements.txt
├── 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
└── 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
9.33.5.1. Prerequisites
The segmentation mask image file in MetaImage or NIfTI format, as well as segment labels
The original dcm files from the single DICOM series used for the segmentation
9.33.5.2. Step 1
Change to your working directory (e.g. my_test
).
9.33.5.3. 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 Segmentation dcm file.logs
for log files.
9.33.5.4. Step 3
In your working directory, create a shell script (e.g. run_app_docker.sh
or other name if you prefer), copy and paste the sample content below, modify the variable APP_NAME
to that of the Docker Image name and tag, and save the file.
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
TESTDATA_DIR=$(readlink -f "${SCRIPT_DIR}"/test-data)
APP_NAME="dicomseg_writer:latest"
INPUT_TYPE="mhd"
# Build Docker image. Which is not needed if the Docker image has been pulled.
# docker build -t ${APP_NAME} -f ${SCRIPT_DIR}/Dockerfile ${SCRIPT_DIR}
# Run ${APP_NAME} container.
docker run -t --name test_dicomseg_writer --rm \
-v ${TESTDATA_DIR}/${INPUT_TYPE}:/input \
-v ${SCRIPT_DIR}/output:/output \
-v ${SCRIPT_DIR}/logs:/logs \
-v ${TESTDATA_DIR}/dcm:/dcm \
-e DEBUG_VSCODE \
-e DEBUG_VSCODE_PORT \
-e NVIDIA_CLARA_NOSYNCLOCK=TRUE \
-e NVIDIA_SEG_LABELS=[\"test-label\"] \
${APP_NAME}
echo "${APP_NAME}has finished."
9.33.5.5. Step 4
Execute the script below and wait for the application container to finish:
./run_app_docker.sh
9.33.5.6. Step 5
Check for the following output files:
The segmentation results in the
output
directoryA file with the same name as the input file, suffixed with
-DICOMSEG
and the extension.dcm
.
9.33.5.7. Step 6
To visualize the results, use 3D Slicer or another DICOM viewer that supports DICOM SEG. For detailed steps, see the viewer documentation. The key steps are as follows:
Import the DICOM Segmentation dcm file as well as the original DICOM series.
Load both the original and the SEG series.
Scroll through the slices.
To view 3D rendering, select the
Volume Rendering
module and enable the loaded volume.
If you want to see the internals of the container and/or manually run the application inside the container, follow these steps:
Start the container in a interactive session. Tp do this, you need to modify the sample script above by replacing
docker run -t
withdocker run -it --entrypoint /bin/bash
, and then run the script file.Once in the container terminal, ensure the current directory is
/app
.Check
/input
and/dcm
have the expected image file(s) and DICOM instance files respectively.Check
/output
and/logs
folders and remove existing files if any.Enter the command
python ./main.py
, and watch the application execute and finish in under 200 ms.Check the
output
folder for the newly created DICOM file.Enter command
exit
to exit the container.
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.
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.