Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/anbhimi/Niffler into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
anbhimi committed Mar 8, 2022
2 parents cce6022 + fbba819 commit be2af07
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modules/png-extraction/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
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"]
38 changes: 38 additions & 0 deletions modules/png-extraction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions modules/png-extraction/png-extraction-docker
Original file line number Diff line number Diff line change
@@ -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 . --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

0 comments on commit be2af07

Please sign in to comment.