Giter Club home page Giter Club logo

pydeface's Introduction

DOI

PyDeface

A tool to remove facial structure from MRI images.

Dependencies:

Package Tested version
FSL 6.0.3
Python 3 3.7.3
NumPy 1.21.6
NiBabel 4.0.1
Nipype 1.5.1

Installation

pip install pydeface

or

git clone https://github.com/poldracklab/pydeface.git
cd pydeface
python setup.py install

How to use

pydeface infile.nii.gz

Also see the help for additional options:

pydeface --help

License

PyDeface is licensed under MIT license.

pydeface's People

Contributors

chrisgorgo avatar effigies avatar leej3 avatar ofgulban avatar poldrack avatar satra avatar shotgunosine avatar vsoch avatar ylep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydeface's Issues

nibabel.deprecator.ExpiredDeprecationError

Hi,

I get the following exception when I deface, and issue appears to be line 124 in utils.py where get_affine() is used, which is deprecated. Has anyone addressed this issue? Thanks!

pydeface 2.0.0
--------------
Temporary files:
  /tmp/tmp_c45u0hf.mat
  /tmp/tmp9_yxyidm.nii.gz
Defacing...
  /mnt/c/data/temp/PRISM2_NL-98-9998_V1_Struc.nii.gz
Traceback (most recent call last):
  File "/home/amalik/anaconda3/bin/pydeface", line 8, in <module>
    sys.exit(main())
  File "/home/amalik/anaconda3/lib/python3.9/site-packages/pydeface/__main__.py", line 95, in main
    pdu.deface_image(**vars(args))
  File "/home/amalik/anaconda3/lib/python3.9/site-packages/pydeface/utils.py", line 124, in deface_image
    masked_brain = Nifti1Image(outdata, infile_img.get_affine(),
  File "/home/amalik/anaconda3/lib/python3.9/site-packages/nibabel/deprecator.py", line 181, in deprecated_func
    raise error_class(message)
nibabel.deprecator.ExpiredDeprecationError: get_affine method is deprecated.
Please use the ``img.affine`` property instead.

* deprecated from version: 2.1
* Raises <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 4.0

t2w scan defacing

Hi I was wondering about the best way to get robust T2w defacing and thoughts on whether changing the code a bit would be desired.

Currently the best way seems to be to deface a T1w scan and then pass the result as a template for subsequent pydeface run for defacing a T2w scan. Alternatively one could register all scans to the T1w scans first and then use the --applyto option. My questions are:
a) Would it be worthwhile integrating this into a more convenient interface i.e. pass pydeface a T1w scan and a list of other scans. Pydeface would first deface the T1w and then use the result as a template for the subsequent scans. Effectively a --applyto_with_reg flag.
b) Would it be worthwhile to use something like epi_reg to make this more robust?
c) Can I submit a pull request documenting outlining the best way to deface these types of scans. My naive attempts had me just defacing T2w with the default template and hacking off large portions of the brain.

[feature request] provide dicom directory as input

There are some great workflows to convert a directory of dicoms into a BIDS compliant format. However, the source dicoms remain identifiable which limits the ability to share source data. At our institute, we have encountered some instances where the source dicoms were requested in-place of the nifti files.

Would it be possible to add functionality for pydeface to accept a directory of dicoms and return defaced dicoms (assuming conversion to nifti and back)?

Strange error message

I'm receiving a strange error message when trying to install pydeface:

running install
running bdist_egg
running egg_info
writing pydeface.egg-info/PKG-INFO
writing dependency_links to pydeface.egg-info/dependency_links.txt
writing entry points to pydeface.egg-info/entry_points.txt
writing requirements to pydeface.egg-info/requires.txt
writing top-level names to pydeface.egg-info/top_level.txt
reading manifest file 'pydeface.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pydeface.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.6-intel/egg
running install_lib
running build_py
creating build/bdist.macosx-10.6-intel/egg
creating build/bdist.macosx-10.6-intel/egg/pydeface
copying build/lib/pydeface/__init__.py -> build/bdist.macosx-10.6-intel/egg/pydeface
copying build/lib/pydeface/utils.py -> build/bdist.macosx-10.6-intel/egg/pydeface
creating build/bdist.macosx-10.6-intel/egg/pydeface/data
copying build/lib/pydeface/data/mean_reg2mean.nii.gz -> build/bdist.macosx-10.6-intel/egg/pydeface/data
copying build/lib/pydeface/data/facemask.nii.gz -> build/bdist.macosx-10.6-intel/egg/pydeface/data
copying build/lib/pydeface/__main__.py -> build/bdist.macosx-10.6-intel/egg/pydeface
byte-compiling build/bdist.macosx-10.6-intel/egg/pydeface/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.macosx-10.6-intel/egg/pydeface/utils.py to utils.cpython-36.pyc
byte-compiling build/bdist.macosx-10.6-intel/egg/pydeface/__main__.py to __main__.cpython-36.pyc
creating build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pydeface.egg-info/PKG-INFO -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pydeface.egg-info/SOURCES.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pydeface.egg-info/dependency_links.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pydeface.egg-info/entry_points.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pydeface.egg-info/requires.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pydeface.egg-info/top_level.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/pydeface-2.0-py3.6.egg' and adding 'build/bdist.macosx-10.6-intel/egg' to it
removing 'build/bdist.macosx-10.6-intel/egg' (and everything under it)
Processing pydeface-2.0-py3.6.egg
Removing /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydeface-2.0-py3.6.egg
Copying pydeface-2.0-py3.6.egg to /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
pydeface 2.0 is already the active version in easy-install.pth
Installing pydeface script to /Library/Frameworks/Python.framework/Versions/3.6/bin

Installed /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydeface-2.0-py3.6.egg
Processing dependencies for pydeface==2.0
Searching for numpy
Reading https://pypi.python.org/simple/numpy/
Downloading https://files.pythonhosted.org/packages/d3/4b/f9f4b96c0b1ba43d28a5bdc4b64f0b9d3fbcf31313a51bc766942866a7c7/numpy-1.16.4.zip#sha256=7242be12a58fec245ee9734e625964b97cf7e3f2f7d016603f9e56660ce479c7
Best match: numpy 1.16.4
Processing numpy-1.16.4.zip
Writing /var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/setup.cfg
Running numpy-1.16.4/setup.py -q bdist_egg --dist-dir /var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/egg-dist-tmp-x4uhsz25
Running from numpy source directory.
/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/setup.py:390: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
  run_build = parse_setuppy_commands()
non-existing path in 'numpy/distutils': 'site.cfg'
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'define_macros'
  warnings.warn(msg)
Could not locate executable gfortran
Could not locate executable f95
Could not locate executable f90
Could not locate executable f77
Could not locate executable xlf90
Could not locate executable xlf
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable g77
Could not locate executable g95
Could not locate executable pgfortran
don't know how to compile Fortran code on platform 'posix'
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 157, in save_modules
    yield saved
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 198, in setup_context
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 248, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 278, in run
    return func()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 246, in runner
    _execfile(setup_script, ns)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 47, in _execfile
    exec(code, globals, locals)
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/setup.py", line 415, in <module>
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/setup.py", line 407, in setup_package
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/core.py", line 171, in setup
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/bdist_egg.py", line 152, in run
    self.run_command("egg_info")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/egg_info.py", line 26, in run
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 148, in run
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 159, in build_sources
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 292, in build_library_sources
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 375, in generate_sources
  File "numpy/core/setup.py", line 667, in get_mathlib_info
RuntimeError: Broken toolchain: cannot link a simple C program

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 47, in <module>
    'pydeface = pydeface.__main__:main'
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/install.py", line 117, in do_egg_install
    cmd.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 410, in run
    self.easy_install(spec, not self.no_deps)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 646, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 697, in install_item
    self.process_distribution(spec, dist, deps)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 742, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 850, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1122, in best_match
    return self.obtain(req, installer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1134, in obtain
    return installer(requirement)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 665, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 695, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 876, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 1115, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 1101, in run_setup
    run_setup(setup_script, args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 251, in run_setup
    raise
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 100, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 198, in setup_context
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 100, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 169, in save_modules
    saved_exc.resume()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 144, in resume
    six.reraise(type, exc, self._tb)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/_vendor/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 157, in save_modules
    yield saved
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 198, in setup_context
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 248, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 278, in run
    return func()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 246, in runner
    _execfile(setup_script, ns)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/sandbox.py", line 47, in _execfile
    exec(code, globals, locals)
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/setup.py", line 415, in <module>
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/setup.py", line 407, in setup_package
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/core.py", line 171, in setup
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/bdist_egg.py", line 152, in run
    self.run_command("egg_info")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/egg_info.py", line 26, in run
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 148, in run
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 159, in build_sources
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 292, in build_library_sources
  File "/var/folders/lz/fhyd7st94td_q0cwz3vl6svr0000gn/T/easy_install-ol_r_qq4/numpy-1.16.4/numpy/distutils/command/build_src.py", line 375, in generate_sources
  File "numpy/core/setup.py", line 667, in get_mathlib_info
RuntimeError: Broken toolchain: cannot link a simple C program
---
This is the full conda list in my environment, showing numpy is there:

# Name                    Version                   Build  Channel
appnope                   0.1.0            py36hf537a9a_0  
attrs                     19.1.0                   py36_1  
backcall                  0.1.0                    py36_0  
blas                      1.0                         mkl  
bleach                    3.1.0                    py36_0  
brainiak                  0.8                      pypi_0    pypi
bz2file                   0.98                     py36_1  
ca-certificates           2019.6.16            hecc5488_0    conda-forge
cctools                   895                           1  
certifi                   2019.3.9                 py36_0    conda-forge
clang                     4.0.1                         1  
clang_osx-64              4.0.1               h1ce6c1d_16  
clangxx                   4.0.1                         1  
clangxx_osx-64            4.0.1               h22b1bf0_16  
click                     7.0                        py_0    conda-forge
compiler-rt               4.0.1                hcfea43d_1  
cycler                    0.10.0           py36hfc81398_0  
cython                    0.29.8           py36h0a44026_0  
dbus                      1.13.6               h90a0687_0  
decorator                 4.4.0                    py36_1  
defusedxml                0.6.0                      py_0  
entrypoints               0.3                      py36_0  
expat                     2.2.6                h0a44026_0  
freetype                  2.9.1                hb4e5f40_0  
funcsigs                  1.0.2                      py_3    conda-forge
future                    0.17.1                py36_1000    conda-forge
gettext                   0.19.8.1             h15daf44_3  
glib                      2.56.2               hd9629dc_0  
h5py                      2.9.0            py36h3134771_0  
hdf5                      1.10.4               hfa1e0ec_0  
html5lib                  1.0.1                      py_0    conda-forge
icu                       58.2                 h4b95b61_1  
intel-openmp              2019.4                      233  
ipykernel                 5.1.0            py36h39e3cac_0  
ipython                   7.5.0            py36h39e3cac_0  
ipython_genutils          0.2.0            py36h241746c_0  
ipywidgets                7.4.2                    py36_0  
isodate                   0.6.0                      py_1    conda-forge
jedi                      0.13.3                   py36_0  
jinja2                    2.10.1                   py36_0  
joblib                    0.13.2                   py36_0  
jpeg                      9b                   he5867d9_2  
jsonschema                3.0.1                    py36_0  
jupyter                   1.0.0                    py36_7  
jupyter_client            5.2.4                    py36_0  
jupyter_console           6.0.0                    py36_0  
jupyter_core              4.4.0                    py36_0  
keepalive                 0.5                        py_1    conda-forge
kiwisolver                1.1.0            py36h0a44026_0  
ld64                      274.2                         1  
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.2.1                h475c297_4  
libgfortran               3.0.1                h93005f0_2  
libiconv                  1.15                 hdd342a3_7  
libpng                    1.6.37               ha441bb4_0  
libsodium                 1.0.16               h3efe00b_0  
libxml2                   2.9.9                hd80cff7_0    conda-forge
libxslt                   1.1.32            h33a18ac_1002    conda-forge
llvm                      4.0.1                         1  
llvm-lto-tapi             4.0.1                         1  
llvm-meta                 7.0.0                         0    conda-forge
llvm-openmp               4.0.1                hcfea43d_1  
lxml                      4.3.4            py36h08abf6f_0    conda-forge
markupsafe                1.1.1            py36h1de35cc_0  
matplotlib                3.1.0            py36h54f8f79_0  
mistune                   0.8.4            py36h1de35cc_0  
mkl                       2019.4                      233  
mkl-service               2.0.2            py36h1de35cc_0  
mkl_fft                   1.0.12           py36h5e564d8_0  
mkl_random                1.0.2            py36h27c97d8_0  
mpi                       1.0                     openmpi  
mpi4py                    2.0.0                    py36_0  
nbconvert                 5.5.0                      py_0  
nbformat                  4.4.0            py36h827af21_0  
ncurses                   6.1                  h0a44026_1  
networkx                  2.3                        py_0  
neurdflib                 5.0.0.post1                py_0    conda-forge
nibabel                   2.4.1                      py_0    conda-forge
nipype                    1.2.0                    py36_0    conda-forge
nitime                    0.7             py36h917ab60_1002    conda-forge
notebook                  5.7.8                    py36_0  
numpy                     1.15.4                   pypi_0    pypi
numpy-base                1.16.4           py36h6575580_0  
openmp                    7.0.0                h2d50403_0    conda-forge
openmpi                   3.1.3                hfa1e0ec_1  
openssl                   1.1.1b               h01d97ff_2    conda-forge
packaging                 19.0                       py_0    conda-forge
pandas                    0.24.2           py36h0a44026_0  
pandoc                    2.2.3.2                       0  
pandocfilters             1.4.2                    py36_1  
parso                     0.4.0                      py_0  
patsy                     0.5.1                    py36_0  
pcre                      8.43                 h0a44026_0  
pexpect                   4.7.0                    py36_0  
pickleshare               0.7.5                    py36_0  
pip                       19.1.1                   py36_0  
prometheus_client         0.6.0                    py36_0  
prompt_toolkit            2.0.9                    py36_0  
prov                      1.5.3                      py_0    conda-forge
psutil                    5.6.2            py36h1de35cc_0  
ptyprocess                0.6.0                    py36_0  
pybind11                  2.2.4            py36h04f5b5a_0  
pydicom                   1.2.2                      py_0    conda-forge
pydotplus                 2.0.2                      py_1    conda-forge
pygments                  2.4.0                      py_0  
pymanopt                  0.2.3                    pypi_0    pypi
pyparsing                 2.4.0                      py_0  
pyqt                      5.9.2            py36h655552a_2  
pyrsistent                0.14.11          py36h1de35cc_0  
python                    3.6.8                haf84260_0  
python-dateutil           2.8.0                    py36_0  
pytz                      2019.1                     py_0  
pyzmq                     18.0.0           py36h0a44026_0  
qt                        5.9.7                h468cd18_1  
qtconsole                 4.5.1                      py_0  
rdflib                    4.2.2                 py36_1000    conda-forge
readline                  7.0                  h1de35cc_5  
scikit-learn              0.21.2           py36h27c97d8_0  
scipy                     1.2.1            py36h1410ff5_0  
send2trash                1.5.0                    py36_0  
setuptools                41.0.1                   py36_0  
simplejson                3.16.1           py36h470a237_0    conda-forge
sip                       4.19.8           py36h0a44026_0  
six                       1.12.0                   py36_0  
sparqlwrapper             1.8.2                 py36_1000    conda-forge
sqlite                    3.28.0               ha441bb4_0  
statsmodels               0.9.0            py36h1d22016_0  
terminado                 0.8.2                    py36_0  
testpath                  0.4.2                    py36_0  
theano                    1.0.3            py36h04f5b5a_0  
tk                        8.6.8                ha441bb4_0  
tornado                   6.0.2            py36h1de35cc_0  
traitlets                 4.3.2            py36h65bd3ce_0  
traits                    5.1.1            py36h01d97ff_0    conda-forge
typing                    3.6.4                    py36_0  
wcwidth                   0.1.7            py36h8c6ec74_0  
webencodings              0.5.1                    py36_1  
wheel                     0.33.4                   py36_0  
widgetsnbextension        3.4.2                    py36_0  
xvfbwrapper               0.2.9                 py36_1000    conda-forge
xz                        5.2.4                h1de35cc_4  
zeromq                    4.3.1                h0a44026_3  
zlib                      1.2.11               h1de35cc_3  

Any idea what I'm doing wrong?

How to cite you?

Hi,
Thank you for this amazing tool!
can you please tell me how I can cite you in my thesis?
Many thanks :)

pydeface will choke on '(' in filename

Hi all,
just ran into this error today:

pydeface --outfile /tmp/test.nii '/Library/researchdata/1220/20170616-103118_MRI/1220-VERBG_PRE15(t-test,_MC)-602.nii'
--------------
pydeface 2.0.2
--------------
Temporary files:
  /tmp/tmpgadexfnj.mat
  /tmp/tmpov9w01f0.nii.gz
Defacing...
  /Library/researchdata/1220/20170616-103118_MRI/1220-VERBG_PRE15(t-test,_MC)-602.nii
221216-13:27:34,90 nipype.interface INFO:
	 stderr 2022-12-16T13:27:34.090563:/bin/sh: 1: Syntax error: "(" unexpected
221216-13:27:34,130 nipype.interface INFO:
	 stderr 2022-12-16T13:27:34.130592:/bin/sh: 1: Syntax error: "(" unexpected
Traceback (most recent call last):
  File "/usr/local/bin/pydeface", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/pydeface/__main__.py", line 95, in main
    pdu.deface_image(**vars(args))
  File "/usr/local/lib/python3.9/dist-packages/pydeface/utils.py", line 117, in deface_image
    warped_mask_img = load(warped_mask)
  File "/usr/local/lib/python3.9/dist-packages/nibabel/loadsave.py", line 94, in load
    raise ImageFileError(f"Empty file: '{filename}'")
nibabel.filebasedimages.ImageFileError: Empty file: '/tmp/tmpov9w01f0.nii.gz'

where it seems nipype(?) chocked on the '(' on the command line.

shutil has no attribute 'which'

I get the error below when I try to run pydeface. It looks like it is grabbing shutil from my python 2.7 environment, which does not have the "which". It does so even if I run pydeface from my python 3.7 environment. Thanks.

Traceback (most recent call last):

File "/Users/kohler/anaconda2/bin/pydeface", line 11, in
load_entry_point('pydeface==2.0', 'console_scripts', 'pydeface')()
File "/Users/kohler/code/git/pydeface/pydeface/main.py", line 116, in main
pdu.deface_image(**vars(args))
File "/Users/kohler/code/git/pydeface/pydeface/utils.py", line 83, in deface_image
if shutil.which('fsl') is None:
AttributeError: 'module' object has no attribute 'which'

defacing issue crop image

I tried to deface some T1w images (brain and spine up to C7 level). The problem is that the images are cropped to C2 level in the spine.

Is there a way to enlarge the FOV of the pydeface ?

docker image

Hi,

I wanted to get the docker image to run pydeface, unfortunately it doesn't work with tag:latest.

Thank you,

Carina

Versioning and pypi upload ?

For new users it's a bit confusing to see what version to use. Pypi only has 1.0.0 (which is old and still uses python2), Github releases only list 1.0.0 and 1.1.0 and setup.py contains version string 2.0.

A new 2.0 (pre) release(?), a tag and an upload to pypi would be super helpful for us :)

orientation required to match MNI152

Pydeface improperly defaced several images like the one shown in the attached image. It would not deface them properly unless fslreorient2std was run prior to defacing.

bad_pydeface

motion correction before defacing?

A nice tool!
I am thinking of whether the defacing would affect the following data analysis. For example, when aligning the template file to the input file (4D, reference in flirt), only the first volume is used for the registrition. So the defacing could work pefect for the first volume. But if head motion exists in the 4D file, this defacing would lead to masking differently for each following volumes. I am not sure whether this different masking for each volume would affect the motion correction of the defaced data. Perhaps, it would be better to do the defacing after motion correction. What do you think about this issue?

[feature proposal] BIDS directory as input

Hello,

Would it be of interest to add a feature so that pydeface accepts a BIDS directory as input, to make pydeface potentially run as a BIDS app ?

Many implementations are possible, with one possible first iteration e.g. relying on pybids and involving as parameters:

  • a path to a BIDS directory
  • an optional subject (all by default)
  • an optional suffix (T1w by default)

Best practice seems to be replacing the original file with the defaced one so the output could be:

  • the original non defaced file renamed as ..._desc-nondefaced_..._<suffix>.nii.gz
  • saving the defaced file with the name of the original one (or e.g. ..._desc-defaced_...<suffix>.nii.gz)

defacing raw images cut off frontal brain tissue

Hi,
i started using pydeface, but it cut off parts of the brain. It worked fine when using MNI-normalized data, but I wanted to share unprocessed raw data. Are there any additional suggestions that the data should conform to (e.g. resetting the origin?).
Thank you

pydeface usage

Hello,

I wanted to get thoughts on if it matters to use pydeface either before preprocessing of MRI or after preprocessing of MRI?
Preprocessing steps include registration, bias correction and skull stripping.

Thanks,
Rohan

Detail the list of FSL dependencies

I want to use pydeface in a bigger context of data acquisition. I've added FSL into my Dockerfile. The problem is that FSL takes ~2.5h to install and ~16GB of space. I've posted some of the issues in ReproNim/neurodocker#450

I'm wandering if I could at least reduce the container size by specifying more precise FSL dependencies, for example, FLIRT.

Here is the list of top-level directories in FSL directory and their sizes:

root@6778f59b8716:/opt/fsl-6.0.5.1# du -sh *
4.0K    LICENCE
4.0K    README
4.4G    bin
8.0K    build
3.1M    build.log
152K    config
2.3G    data
188M    doc
5.0M    etc
339M    extras
6.3G    fslpython
4.7M    include
1.6G    lib
264K    python
324K    refdoc
257M    src
2.4M    tcl

defacing fails if environment variable FSLOUTPUTTYPE != NIFTI_GZ

Causes flirt interface to make output files based on FSLOUTPUTTYPE, but pydeface looks for .nii.gz

$ echo $FSLOUTPUTTYPE
NIFTI
$ pydeface.py sub-1700/anat/sub-1700_T1w.nii.gz test.nii
defacing sub-1700/anat/sub-1700_T1w.nii.gz
Traceback (most recent call last):
  File "/work/03872/wtriplet/lonestar/anaconda/bin/pydeface.py", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home1/03872/wtriplet/software/pydeface/scripts/pydeface.py", line 143, in <module>
    main()
  File "/home1/03872/wtriplet/software/pydeface/scripts/pydeface.py", line 127, in main
    flirt.run()
  File "/home1/03872/wtriplet/software/nipype/nipype/interfaces/base.py", line 1046, in run
    outputs = self.aggregate_outputs(runtime)
  File "/home1/03872/wtriplet/software/nipype/nipype/interfaces/fsl/preprocess.py", line 550, in aggregate_outputs
    runtime=runtime, needed_outputs=needed_outputs)
  File "/home1/03872/wtriplet/software/nipype/nipype/interfaces/base.py", line 1140, in aggregate_outputs
    raise FileNotFoundError(msg)
nipype.utils.filemanip.FileNotFoundError: File/Directory '/tmp/tmpzLbhge.nii.gz' not found for FLIRT output 'out_file'.
Interface FLIRT failed to run.
$ ls /tmp/tmpzLbhge.nii
/tmp/tmpzLbhge.nii

How to save defaced output in a different directory (from input) when using --applyto argument.

I am using pydeface 2.0.2 on docker. Following is the command I am using to deface my multiple .nii files using --applyto argument:

docker run -v /home/ .. /outputs:/output -v /home/ .. /inputs/:/input pydeface:0.1.2 pydeface --outfile /output/defaced.nii.gz --applyto /input/*.nii.gz --outfile /output/ --force /input/sample_file_1.nii.gz

Pydeface command is basically as follows:

pydeface --outfile /output/defaced.nii.gz --applyto /input/*.nii.gz --outfile /output/ --force /input/sample_file_1.nii.gz

This works fine and save the defaced output in my input directory and not in the outfile directory where I want to store the output. Can you please let me know what corrections can be made to save defaced output in a separate directory to that of input using --applyto argument?

Thanks

Improper defacing before reorient

Hello,

For some subjects we have, parts of the brain are cut off instead of the face (see below images). However, pydeface seems to work when the image is reoriented first

You should be able to reproduce this issue by doing

curl https://patrickstetz.com/pydeface/in.nii.gz --output in.nii.gz
singularity run --cleanenv -B ./:/tmp/0 docker://poldracklab/pydeface pydeface ./in.nii.gz

Input Image

in

After defacing

in_deface

Defacing after reorienting first

reorient_deface

Would be happy to help by submitting a PR for this!!

Best,
Patrick

Mark images as defaced

Question came up on Neurostars about detecting already defaced images: https://neurostars.org/t/is-it-an-issue-to-run-pydeface-twice/16866

The general problem is difficult, but we could make people's lives easier by marking images as defaced in the descrip header field (at least for NIfTI images):

defaced = nb.load(..., mmap=False)
descrip = f"pydeface {__version__}".encode()
if defaced.header["descrip"]:
    descrip += b"; " + defaced.header["descrip"]
defaced.header[descrip] = descrip[:80]
defaced.to_filename(...)

inconsistent defacing results

We're finding inconsistent results in defacing depending on the hardware and minor dependency version changes. In the image below, the red is:

  • pydeface 2.0.2
  • fsl 6.0.4
  • python 3.10.4
  • OS Ventura 13.2.1 on Intel Mac

...and the green is:

  • pydeface 2.0.2
  • fsl 6.0.5.1
  • python 3.10.1
  • OS debian:bullseye-slim (run in Docker with --platform=linux/x86_64 on an M1 Mac, fwiw)

The green is what we see with pydeface 2.0.0 and 2.0.2 on fsl 5 and 6 on a variety of python/debian version combinations; so far it's only the Mac that's different. Unfortunately, the green is also obviously not very well defaced. (The red has its own defacing problems, of course, just different ones.) The original nifti is a normalized PDw high-resolution scan targeting the locus coeruleus.

Does anyone have any thoughts as to why we're seeing different results on different hardware platforms?

Screenshot 2023-03-29 at 10 23 30 AM

Outputs to judge success? (aka face still included)

Hello Pydeface repo,

I was just trying to deface some data so that I can put it up on openneuro, but ran into some issues with pydeface. I tried it w/ one sub and had success... However, when I tried to deface a pediatric T1 volume, the face was still present (screengrab below).

deface

Are there other outputs I'm missing from the program that might give some indication of success? The software looked to run without error (command-line output below), but I wondered if there were other files I should inspect to understand why things didn't work out.

jamielh@pfc:~/Volumes/Hanson/Duke_PAC/BIDS_test/derivatives/sub-2014031318263/anat$ pydeface.py sub-${BIDS_sub}_T1w.nii.gz
('defacing', 'sub-2014031318263_T1w.nii.gz')
jamielh@pfc:~/Volumes/Hanson/Duke_PAC/BIDS_test/derivatives/sub-2014031318263/anat$ ls
sub-2014031318263_T1w_defaced.nii.gz  sub-2014031318263_T1w.nii.gz

Any suggestions are greatly appreciated!

Thanks much!
Jamie.

Wrong registration with given mask and template

I use this command to run defacing:

pydeface [my data] --template pydeface/data/mean_reg2mean.nii.gz --facemask pydeface/data/facemask.nii.gz

It runs a long time and I got the output below. It seems that the registration was wrong. Do you know how can I solve this? Which template and mask should I use? Thank you!
image

FSL dependency check requires the complete FSL installation

I'm working on a Docker image for one of our pipelines. Pydeface is one of the tools in the chain. It depends on FSL. The complete FSL installation is time consuming and the resulting image is large. Pydeface seems to use only FLIRT binary out of many FSL tools. I managed to compile FLIRT from sources in my Docker image. The FLIRT binary is only 1MB large + its dependencies.

Unfortunately, pydeface is looking for the fsl binary and not flirt and I fail to execute it. Are there more dependencies than FLIRT from the FSL tools? Could the check be simply substituted with flirt?

According to the documentation, fsl binary is just a menu:

To bring up a simple GUI which is just a menu of the main individual FSL GUI tools, just type fsl.

The following lines allowed me to successfully install and execute pydeface with only flirt binary.

RUN pipx install pydeface
RUN sed -i "s/shutil.which('fsl')/shutil.which('flirt')/g" /root/.local/pipx/venvs/pydeface/lib/python3.11/site-packages/pydeface/utils.py

incomplete defacing

Hi,
Loving this software. During a recent defacing batch, one of my subjects T2w (although T1w fine) image ended up with most of the face left intact. Attached is a screenshot. Any thoughts here? I can use other utilities but prefer pydeface.
Thanks!
Patrick
openneuro_incom

Issue using pydeface on linux VM

Hi all,

We're running into issues de-facing anatomical files on our lab's linux VM. Please note that this issue does not arise when running pydeface on a mac. Here's the error we get when running pydeface:

Defacing...
  sub-014_ses-1_T1w.nii.gz
Traceback (most recent call last):
  File "/PathLocalToMyComputer/anaconda3/bin/pydeface", line 8, in <module>
    sys.exit(main())
  File "/PathLocalToMyComputer/anaconda3/lib/python3.9/site-packages/pydeface/__main__.py", line 95, in main
    pdu.deface_image(**vars(args))
  File "/PathLocalToMyComputer/anaconda3/lib/python3.9/site-packages/pydeface/utils.py", line 124, in deface_image
    masked_brain = Nifti1Image(outdata, infile_img.get_affine(),
  File "/PathLocalToMyComputer/anaconda3/lib/python3.9/site-packages/nibabel/deprecator.py", line 181, in deprecated_func
    raise error_class(message)
nibabel.deprecator.ExpiredDeprecationError: get_affine method is deprecated.
Please use the ``img.affine`` property instead.

* deprecated from version: 2.1
* Raises <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 4.0

Has anyone encountered a similar issue?

Thanks,
Frank

Further Nipypification

Pydeface is currently just using a few fsl interfaces from nipype, but to integrate it into the niworkflows ecosystem, it would be better if pydefaces utilities actually generated nipype workflows. I've started a work in progress PR #24 as a first attempt at this, but I wanted to get some feedback. Is nipypification of pydeface worth the cost of overhauling the python interface?

AttributeError: 'module' object has no attribute 'which'

I installed pydeface on my CentOS 7.6, and my python version is 2.7.5
I got the following message when running pydeface on my data

Traceback (most recent call last):
  File "/usr/bin/pydeface", line 11, in <module>
    load_entry_point('pydeface==2.0', 'console_scripts', 'pydeface')()
  File "build/bdist.linux-x86_64/egg/pydeface/__main__.py", line 116, in main
  File "build/bdist.linux-x86_64/egg/pydeface/utils.py", line 83, in deface_image
AttributeError: 'module' object has no attribute 'which'

I heard that 'module' object has 'which' after 3.3 version of python.
But I do not think pydeface is orginally developed for python3, and only work on python3 ?
Any one could help me ?

Reduce time needed for defacing

Hello,

I'm defacing my anatomical data using version 2.0, and have noticed on different datasets that the defacing can take anywhere from 2-3 minutes for some anatomical images, to 8-10 minutes for others. Other than potential data quality issues, such as motion artifacts and/or poor CNR, are there other factors that can increase the time, such as slow HPC I/O? I'm trying to see if there is anything I can do to reduce the time.

Thanks!

FSL Not Found on Path for pydeface

A user in my building has requested help with this issue. I must preface this by saying I have no experience in this matter and minimal Linux experience, however due to departmental downsizing and limitation, I am the one who was given this to investigate. Please be understanding.

This was their exact message to me:

In early May, we had FSL (FMRib Software Library, a neuroimaging analysis program) installed for use on the server in our lab. FSL did install successfully and can be accessed by using the command fsl5.0-fsl, and works perfectly when being used directly.
However, since installation of FSL, when trying to use other tools which look for or attempt to use FSL, I've had some trouble; they seem not to be able to detect that FSL has been installed. I'm not sure if that's because they're trying to access it via, for example, a simpler command such as "fsl" by itself, or whether that's unrelated.
Most recently this has been an issue with my attempt to use pydeface to anonymize MRI data for archiving on a public platform. Here is what happens when I try to run pydeface:

username@server:~/{data_path redacted}/Raw$ pydeface s103/003/003_t1_mprage_sag_ns_20180416115703_3.nii 
--------------
pydeface 2.0.2
--------------
Traceback (most recent call last):
  File "/home/username/.local/bin/pydeface", line 8, in <module>
    sys.exit(main())
  File "/home/username/.local/lib/python3.8/site-packages/pydeface/__main__.py", line 95, in main
    pdu.deface_image(**vars(args))
  File "/home/username/.local/lib/python3.8/site-packages/pydeface/utils.py", line 84, in deface_image
    raise EnvironmentError("fsl cannot be found on the path")
OSError: fsl cannot be found on the path

Is the issue with the path in my personal profile, or with the way FSL is accessed, or possibly elsewhere?"

I will provide whatever information is helpful or needed if anyone has some ideas what is going on here. The person in my department who had experience with these installations is no longer available for me to call upon.

Best,
Brian

Not quite defaced

Hello.

I've run pydeface (2.0.0) on a test image, but the App is not quite completely defacing.

image

I see that I can set template / facemask, etc.. parameters with pydeface, but I am not sure which knobs to tweak to get it properly defaced in this case. Do you have any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.