Sikerdebaard / dcmrtstruct2nii

DICOM RT-Struct to mask
MIT License
91 stars 27 forks source link

Extremly high memory consumption #8

Closed Karol-G closed 3 years ago

Karol-G commented 3 years ago

Hi,

I wanted to convert a dataset with your cool tool and for most of it it worked like a charm :) However for a couple files I got an extremly high memory consumption (used up to 60GB on a machine with 62GB RAM) that the process got terminated by the system. Do you know why that could be?

Best Karol

Sikerdebaard commented 3 years ago

Images are loaded fully into the memory. Whats the dimensions of your dicom? :)

Karol-G commented 3 years ago

Thanks for the quick reply! The dimensions for this one problematic case is 1280x1280x249.

Sikerdebaard commented 3 years ago

Are you converting multiple masks in the rtstruct? If so you could try selecting only the relevant mask using the -s option

dcmrtstruct2nii convert --help
USAGE
  console convert [-r <...>] [-d <...>] [-o <...>] [-g [<...>]] [-s [<...>]] [-f [<...>]] [-b [<...>]] [-c [<...>]]

OPTIONS
  -r (--rtstruct)                Path to DICOM RT Struct file, example: /tmp/DICOM/resources/secondary/rtstruct.dcm
  -d (--dicom)                   Path to original DICOM file, example: /tmp/DICOM/resources/files
  -o (--output)                  Output path, example: /tmp/output
  -g (--gzip)                    Optional, gzip output .nii (default: "true")
  -s (--structures)              Optional, list of structures that need to be converted, example: Patient, Spinal, Dose-1
  -f (--mask-foreground-color)   Optional, the foreground color used for the mask. Must be between 0-255. (default: "255")
  -b (--mask-background-color)   Optional, the background color used for the mask. Must be between 0-255. (default: "0")
  -c (--convert-original-dicom)  Optional, convert the original dicom to nii (default: "true")

GLOBAL OPTIONS
  -h (--help)                    Display this help message
  -q (--quiet)                   Do not output any message
  -v (--verbose)                 Increase the verbosity of messages: "-v" for normal output, "-vv" for more verbose output and "-vvv" for debug
  -V (--version)                 Display this application version
  --ansi                         Force ANSI output
  --no-ansi                      Disable ANSI output
  -n (--no-interaction)          Do not ask any interactive question

If you need all the masks you could try a script like below to convert them one-by-one.

#!/bin/bash
# extract_one_by_one.sh

STRUCTS=(`dcmrtstruct2nii list --rtstruct $1`)

dcmrtstruct2nii convert --rtstruct $1 --dicom $2 --output $3 -s ${STRUCTS[0]}

echo $STRUCTS
for el in "${STRUCTS[@]:1}"
   do  dcmrtstruct2nii convert --rtstruct $1 --dicom $2 --output $3 -c no -s "$el"
done

Which you would then call like ./extract_one_by_one.sh /path/to/rtstruct /path/to/dicom /output/dir

Karol-G commented 3 years ago

Sorry for the late reply! I managed to avoid the process termination now by using a machine with 255GB of memory. Some of the cases used up to 240GB, but they got converted. I did not test if your approach works, but will probably in the future if I have time again. But thanks for your help! Closing this for now.

Best Karol