From 23dc5db9e63c9e185236d8c09559aae3577272d3 Mon Sep 17 00:00:00 2001 From: Nitesh639 Date: Mon, 7 Mar 2022 22:00:34 -0600 Subject: [PATCH 1/3] Added docker contenariztion to png-extraction module --- modules/png-extraction/Dockerfile | 12 ++++ modules/png-extraction/png-extraction-docker | 74 ++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 modules/png-extraction/Dockerfile create mode 100644 modules/png-extraction/png-extraction-docker diff --git a/modules/png-extraction/Dockerfile b/modules/png-extraction/Dockerfile new file mode 100644 index 0000000..66c1b17 --- /dev/null +++ b/modules/png-extraction/Dockerfile @@ -0,0 +1,12 @@ +FROM ravirahar/arch-python-gdcm +ARG DICOMHome="/opt/data/new-study" + +COPY . /png-extraction +COPY $DICOMHome /png-extraction/dicom_home +WORKDIR /png-extraction + +RUN chmod -R a+rw /png-extraction +RUN chown -R $USER:users /png-extraction +RUN chmod +x ./png-extraction-docker + +CMD ["./png-extraction-docker", "--docker"] diff --git a/modules/png-extraction/png-extraction-docker b/modules/png-extraction/png-extraction-docker new file mode 100644 index 0000000..ace0082 --- /dev/null +++ b/modules/png-extraction/png-extraction-docker @@ -0,0 +1,74 @@ +#!/bin/sh + +cmd="python3 ImageExtractor.py" +# With Nohup +# cmd=nohup python3 ImageExtractor.py > UNIQUE-OUTPUT-FILE-FOR-YOUR-EXTRACTION.out & + +# With Command Line Arguments +# cmd=nohup python3 ImageExtractor.py --Depth 0 --PrintImages true --SendEmail true > UNIQUE-OUTPUT-FILE-FOR-YOUR-EXTRACTION.out & + +dicom_home=${2:-/opt/data/new-study} +output_dir=${3:-/opt/data/new-study/root} + +case $1 in + + -d|--docker) + + echo "EXECUTING ..." + + ${cmd} + + echo "EXITING ..." + ;; + + -r|--run) + sed -i.bak "s/DICOMHome.*/DICOMHome\":\ \"dicom_home\",/" config.json + sed -i "s/OutputDirectory.*/OutputDirectory\":\ \"output\",/" config.json + + sudo docker build -t png-extraction . --no-cache --build-arg DICOMHome=${dicom_home} + sudo docker run -it png-extraction + sudo docker cp $(sudo docker ps -a --no-trunc -q -n 1):/png-extraction/output ${output_dir} + + sudo find ${output_dir} -type d -exec chmod 755 {} \; + sudo find ${output_dir} -type f -exec chmod 644 {} \; + sudo chown -R $USER:users ${output_dir} + + mv config.json.bak config.json + ;; + + -h|--help) + + __usage=" + Usage: $(basename $0) -r + or + $(basename $0) --run [DICOMHome] [OutputDirectory] + + Example: + $(basename $0) -r /opt/data/new-study /opt/data/new-study/root + + Defaults: + DICOMHome = /opt/data/new-study + OutputDirectory = /opt/data/new-study/root + + Options: + -d, --docker Meant to be used by docker when building, + not to be used by user + -h, --help Print this help page + + " + + echo "$__usage" + ;; + + *) + __invalid_arg=" + Please provide a valid argument. + Run following for more help: + + $(basename $0) --help + " + echo "$__invalid_arg" + ;; + + +esac From 4338c72b4f832a28c6661b07165940654a8c750b Mon Sep 17 00:00:00 2001 From: Nitesh639 Date: Mon, 7 Mar 2022 22:05:30 -0600 Subject: [PATCH 2/3] Updated README.md with docker instructions --- modules/png-extraction/README.md | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modules/png-extraction/README.md b/modules/png-extraction/README.md index cac8e91..508db33 100644 --- a/modules/png-extraction/README.md +++ b/modules/png-extraction/README.md @@ -73,6 +73,44 @@ In the OutputDirectory, there will be several sub folders and directories. There is also an experimental PNG extractor implementation (ImageExtractorSlurm.py) that provides a distributed execution based on Slurm on a cluster. +## Running the Niffler PNG Extractor with Docker + +To install docker run: + +```bash + + # Install docker + $ sudo yum install docker + # Start docker service + $ sudo systemctl enable docker.service --now +``` + +To run do: + + +```bash + +# To run with default DICOMHome and OutputDirectory +$ ./png-extraction-docker -r + +# To run with custom DICOMHome and OutputDirectory +$ ./png-extraction-docker -r [DICOMHome] [OutputDirectory] + +``` +Edit the python command to be executed in png-extraction-docker script file. +For example, to run Niffler with Slurm change : + + cmd="python3 ImageExtractor.py" +by + + cmd="python3 ImageExtractorSlurm.py" + +**Note:** +- Do not set DICOMHome and OutputDirectory in config.json, supply them to script in format available. + +- To configure other options, change them in config.json + + ## Troubleshooting If you encounter your images being ending in the failed-dicom/3 folder (the folder signifying base exception), check the From 50349d182207a5be91be809f9df6b4294557c701 Mon Sep 17 00:00:00 2001 From: Nitesh639 Date: Tue, 8 Mar 2022 00:03:24 -0600 Subject: [PATCH 3/3] Updated Dockerfile to use a standard linux image instead of custom used before --- modules/png-extraction/Dockerfile | 9 +++++++-- modules/png-extraction/png-extraction-docker | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/png-extraction/Dockerfile b/modules/png-extraction/Dockerfile index 66c1b17..68ee0ef 100644 --- a/modules/png-extraction/Dockerfile +++ b/modules/png-extraction/Dockerfile @@ -1,5 +1,10 @@ -FROM ravirahar/arch-python-gdcm -ARG DICOMHome="/opt/data/new-study" +FROM ubuntu + +RUN apt-get update && apt-get upgrade -y +RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install --no-install-recommends --no-install-suggests -y tzdata python3 python-is-python3 python3-pip mailutils sendmail libgdcm3.0 libgdcm-tools python3-gdcm python3-pillow python3-pandas python3-numpy +RUN pip install pydicom pypng pylibjpeg + +ARG DICOMHome COPY . /png-extraction COPY $DICOMHome /png-extraction/dicom_home diff --git a/modules/png-extraction/png-extraction-docker b/modules/png-extraction/png-extraction-docker index ace0082..5f91596 100644 --- a/modules/png-extraction/png-extraction-docker +++ b/modules/png-extraction/png-extraction-docker @@ -25,7 +25,7 @@ case $1 in sed -i.bak "s/DICOMHome.*/DICOMHome\":\ \"dicom_home\",/" config.json sed -i "s/OutputDirectory.*/OutputDirectory\":\ \"output\",/" config.json - sudo docker build -t png-extraction . --no-cache --build-arg DICOMHome=${dicom_home} + sudo docker build -t png-extraction . --build-arg DICOMHome=${dicom_home} sudo docker run -it png-extraction sudo docker cp $(sudo docker ps -a --no-trunc -q -n 1):/png-extraction/output ${output_dir}