Pydeface from dcm2bids does not create defaced nifti files

Dear all,

I am new to dcm2bids and I am trying to convert my DICOM data to Bids and at the same time, deface my T1w images ( I have 3 runs of them per subject), everything goes well except it does not create the nifti defaced files (it does create the .rec-deface.json files). Am I missing something?

I am using the last version of dcm2bids 3.2.0 and launching the code in python (I created a virtual environment) using the following command:

dcm2bids -d sourcedata\MYFOLDER\ -p ID01 -c code\dcm2bids_config.json --auto_extract_entities --force_dcm2bids --clobber

My config file is as following:

{

  "post_op": [
        {
            "cmd": "pydeface  --outfile dst_file src_file --force --verbose",
            "datatype": "anat",
            "suffix": "T1w",
            "custom_entities": "rec-defaced"
        }
    ],
  "descriptions": [
   {
       "datatype": "anat",
       "suffix": "T1w",
       "criteria": {
       "SeriesDescription": "t1_mprage_cor_p2_iso",
       "SidecarFilename": "014*"
      }
    },
   {
       "datatype": "anat",
       "suffix": "T1w",
       "criteria": {
       "SeriesDescription": "t1_mprage_cor_p2_iso_MPR_Tra",
       "SidecarFilename": "015*"
      }
    },
   {
       "datatype": "anat",
       "suffix": "T1w",
       "criteria": {
       "SeriesDescription": "t1_mprage_cor_p2_iso_MPR_Sag",
       "SidecarFilename": "016*"
      }
    }

Thanks,

Eva


Hi @EBB,

Did you install pydeface ? Pydeface is not part of dcm2bids you have to install it to be able to use it.
OR you can use a container where everything is already installed: Use container images - dcm2bids documentation

Either way, when you submit an issue you should attach the log file, it helps us a lot.

Hope it helps,
Best,
Arnaud

Hello @abore,

Thank you for your answer! I found the problem :slight_smile:
pydeface is installed:

(dcm2bidsENV) XX>pydeface -h
--------------
pydeface 2.0.2
--------------
usage: pydeface [-h] [--outfile path] [--force] [--applyto  [...]] [--cost mutualinfo] [--template path]
                [--facemask path] [--nocleanup] [--verbose] [--debug]
                path

positional arguments:
  path               Path to input nifti.

options:
  -h, --help         show this help message and exit
  --outfile path     If not provided adds '_defaced' suffix.
  --force            Force to rewrite the output even if it exists.
  --applyto  [ ...]  Apply the created face mask to other images. Can take multiple arguments.
  --cost mutualinfo  FSL-FLIRT cost function. Default is 'mutualinfo'.
  --template path    Optional template image that will be used as the registration target instead of the default.
  --facemask path    Optional face mask image that will be used instead of the default.
  --nocleanup        Do not cleanup temporary files. Off by default.
  --verbose          Show additional status prints. Off by default.
  --debug            Do not catch exceptions and show exception traceback (Drop into pdb debugger).

And when I run it alone, the path from FLS is not found, causing the problem (I don’t have it installed).

pydeface myanatomical.nii.gz

--------------
pydeface 2.0.2
--------------
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "XX\dcm2bidsENV\Scripts\pydeface.exe\__main__.py", line 7, in <module>
  File "XX\dcm2bidsENV\Lib\site-packages\pydeface\__main__.py", line 95, in main
    pdu.deface_image(**vars(args))
  File "XX\dcm2bidsENV\Lib\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

I will try using the container instead, to have everything installed.

Thank you for your help,

Eva