Skip to content

Commit

Permalink
mridefacer fix and update
Browse files Browse the repository at this point in the history
This commit and PR fixes and updates mridefacer, as it crashed based on inconsistencies in the respective function's setup. 
The following files were changed:

- generate_iamges.sh & Dockerfile -> FSL templates were added to the container as they are needed by mridefacer
- defacing_algorithms -> mridefacer commands and workflow were updated to remove problems wrt copying of the face mask & add the --outdir argument to write defaced images to the respective BIDS root directory
- run_deeid -> updated to reflect the changes made in defacing_algorithms
  • Loading branch information
PeerHerholz committed Jun 7, 2021
1 parent 61d389e commit 5ddcc42
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 19 deletions.
123 changes: 121 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Your version: 0.6.0 Latest version: 0.7.0
# Generated by Neurodocker version 0.6.0
# Timestamp: 2021-04-13 14:10:53 UTC
# Timestamp: 2021-06-07 18:59:26 UTC
#
# Thank you for using Neurodocker. If you discover any issues
# or ways to improve this software, please submit an issue or
Expand Down Expand Up @@ -44,6 +44,7 @@ ENTRYPOINT ["/neurodocker/startup.sh"]
RUN apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
fsl-core \
fsl-mni152-templates \
git \
num-utils \
gcc \
Expand Down Expand Up @@ -116,4 +117,122 @@ ENV IS_DOCKER="1"

WORKDIR /tmp/

ENTRYPOINT ["/neurodocker/startup.sh", "bidsonym"]
ENTRYPOINT ["/neurodocker/startup.sh", "bidsonym"]

RUN echo '{ \
\n "pkg_manager": "apt", \
\n "instructions": [ \
\n [ \
\n "base", \
\n "neurodebian:stretch-non-free" \
\n ], \
\n [ \
\n "install", \
\n [ \
\n "fsl-core", \
\n "fsl-mni152-templates", \
\n "git", \
\n "num-utils", \
\n "gcc", \
\n "g++", \
\n "curl", \
\n "build-essential", \
\n "nano" \
\n ] \
\n ], \
\n [ \
\n "run_bash", \
\n "curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs && apt-get install -y npm" \
\n ], \
\n [ \
\n "add_to_entrypoint", \
\n "source /etc/fsl/fsl.sh" \
\n ], \
\n [ \
\n "miniconda", \
\n { \
\n "conda_install": [ \
\n "python=3.6", \
\n "numpy", \
\n "nipype", \
\n "nibabel", \
\n "pandas" \
\n ], \
\n "pip_install": [ \
\n "deepdefacer", \
\n "tensorflow", \
\n "scikit-image" \
\n ], \
\n "create_env": "bidsonym", \
\n "activate": true \
\n } \
\n ], \
\n [ \
\n "run_bash", \
\n "source activate bidsonym && git clone https://github.com/poldracklab/pydeface.git && cd pydeface && python setup.py install && cd -" \
\n ], \
\n [ \
\n "run_bash", \
\n "source activate bidsonym && git clone https://github.com/nipy/quickshear.git && cd quickshear && python setup.py install && cd -" \
\n ], \
\n [ \
\n "run_bash", \
\n "source activate bidsonym && git clone https://github.com/neuronets/nobrainer.git && cd nobrainer && python setup.py install && cd -" \
\n ], \
\n [ \
\n "run_bash", \
\n "mkdir -p /opt/nobrainer/models && cd /opt/nobrainer/models && curl -LJO https://github.com/neuronets/nobrainer-models/releases/download/0.1/brain-extraction-unet-128iso-model.h5 && cd ~ " \
\n ], \
\n [ \
\n "run_bash", \
\n "git clone https://github.com/mih/mridefacer" \
\n ], \
\n [ \
\n "env", \
\n { \
\n "MRIDEFACER_DATA_DIR": "/mridefacer/data" \
\n } \
\n ], \
\n [ \
\n "run_bash", \
\n "npm install -g [email protected]" \
\n ], \
\n [ \
\n "run_bash", \
\n "mkdir /home/mri-deface-detector && cd /home/mri-deface-detector && npm install sharp --unsafe-perm && npm install -g mri-deface-detector --unsafe-perm && cd ~" \
\n ], \
\n [ \
\n "run_bash", \
\n "git clone https://github.com/miykael/gif_your_nifti && cd gif_your_nifti && source activate bidsonym && python setup.py install" \
\n ], \
\n [ \
\n "copy", \
\n [ \
\n ".", \
\n "/home/bm" \
\n ] \
\n ], \
\n [ \
\n "run_bash", \
\n "chmod a+x /home/bm/bidsonym/fs_data/mri_deface" \
\n ], \
\n [ \
\n "run_bash", \
\n "source activate bidsonym && cd /home/bm && pip install -e ." \
\n ], \
\n [ \
\n "env", \
\n { \
\n "IS_DOCKER": "1" \
\n } \
\n ], \
\n [ \
\n "workdir", \
\n "/tmp/" \
\n ], \
\n [ \
\n "entrypoint", \
\n "/neurodocker/startup.sh bidsonym" \
\n ] \
\n ] \
\n}' > /neurodocker/neurodocker_specs.json
21 changes: 7 additions & 14 deletions bidsonym/defacing_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def run_quickshear(image, outfile):
deface_wf.run()


def mridefacer_cmd(image, subject_label, bids_dir):
def mridefacer_cmd(image, T1_file):
"""
Setup mridefacer command.
Expand All @@ -146,20 +146,14 @@ def mridefacer_cmd(image, subject_label, bids_dir):
import os
from shutil import move

cmd = ["/mridefacer/mridefacer", "--apply", image]
outdir = T1_file[:T1_file.rfind('/')]

cmd = ["/mridefacer/mridefacer", "--apply", image, "--outdir", outdir]
check_call(cmd)
path = os.path.join(bids_dir, "sourcedata/bidsonym/sub-%s" % subject_label)
facemask = os.path.join(bids_dir, "sub-%s" % subject_label,
"anat/sub-%s_T1w_defacemask.nii.gz" % subject_label)
if os.path.isdir(path) is True:
move(facemask, os.path.join(path))
else:
os.makedirs(path)
move(facemask, os.path.join(path))
return


def run_mridefacer(image, subject_label, bids_dir):
def run_mridefacer(image, T1_file):
"""
Setup and mridefacer workflow.
Expand All @@ -176,14 +170,13 @@ def run_mridefacer(image, subject_label, bids_dir):
deface_wf = pe.Workflow('deface_wf')
inputnode = pe.Node(niu.IdentityInterface(['in_file']),
name='inputnode')
mridefacer = pe.Node(Function(input_names=['image', 'subject_label', 'bids_dir'],
mridefacer = pe.Node(Function(input_names=['image', 'T1_file'],
output_names=['outfile'],
function=mridefacer_cmd),
name='mridefacer')
deface_wf.connect([(inputnode, mridefacer, [('in_file', 'image')])])
inputnode.inputs.in_file = image
mridefacer.inputs.subject_label = subject_label
mridefacer.inputs.bids_dir = bids_dir
mridefacer.inputs.T1_file = T1_file
deface_wf.run()


Expand Down
4 changes: 2 additions & 2 deletions bidsonym/run_deeid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def run_deeid():

if args.brainextraction is None:
raise Exception("For post defacing quality it is required to run a form of brainextraction"
"on the non-deindentified data. Thus please either indicate bet"
"on the non-deindentified data. Thus please either indicate bet "
"(--brainextration bet) or nobrainer (--brainextraction nobrainer).")

if args.skip_bids_validation:
Expand Down Expand Up @@ -146,7 +146,7 @@ def run_deeid():
elif args.deid == "quickshear":
run_quickshear(source_t1w, T1_file)
elif args.deid == "mridefacer":
run_mridefacer(source_t1w, subject_label, args.bids_dir)
run_mridefacer(source_t1w, T1_file)
elif args.deid == "deepdefacer":
run_deepdefacer(source_t1w, subject_label, args.bids_dir)

Expand Down
2 changes: 1 addition & 1 deletion generate_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ generate_docker() {
docker run --rm kaczmarj/neurodocker:0.6.0 generate docker \
--base neurodebian:stretch-non-free \
--pkg-manager apt \
--install fsl-core git num-utils gcc g++ curl build-essential nano\
--install fsl-core fsl-mni152-templates git num-utils gcc g++ curl build-essential nano\
--run-bash "curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs && apt-get install -y npm"\
--add-to-entrypoint "source /etc/fsl/fsl.sh" \
--miniconda \
Expand Down

0 comments on commit 5ddcc42

Please sign in to comment.