highspeed-defacing-cleanup.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. # ==============================================================================
  3. # SCRIPT INFORMATION:
  4. # ==============================================================================
  5. # SCRIPT: REPLACING ORIGINAL STRUCTURAL IMAGES WITH DEFACED STRUCTURAL IMAGES
  6. # PROJECT: HIGHSPEED
  7. # WRITTEN BY LENNART WITTKUHN, 2018 - 2020
  8. # CONTACT: WITTKUHN AT MPIB HYPHEN BERLIN DOT MPG DOT DE
  9. # MAX PLANCK RESEARCH GROUP NEUROCODE
  10. # MAX PLANCK INSTITUTE FOR HUMAN DEVELOPMENT
  11. # MAX PLANCK UCL CENTRE FOR COMPUTATIONAL PSYCHIATRY AND AGEING RESEARCH
  12. # LENTZEALLEE 94, 14195 BERLIN, GERMANY
  13. # ==============================================================================
  14. # DEFINE ALL PATHS:
  15. # ==============================================================================
  16. # define home directory
  17. PATH_BASE="${HOME}"
  18. # define the name of the current task:
  19. TASK_NAME="pydeface"
  20. # define the name of the project:
  21. PROJECT_NAME="highspeed"
  22. # path to the data directory (in bids format):
  23. PATH_BIDS="${PATH_BASE}/${PROJECT_NAME}/highspeed-bids"
  24. # ==============================================================================
  25. # REMOVE ORIGINAL T1W IMAGES AND REPLACE WITH DEFACED ONES:
  26. # ==============================================================================
  27. for FILE in ${PATH_BIDS}/*/*/anat/*T1w_defaced.nii.gz; do
  28. # to just get filename from a given path:
  29. FILE_BASENAME="$(basename -- $FILE)"
  30. # get the parent path of directories:
  31. FILE_PARENT="$(dirname "$FILE")"
  32. # get the file name without the _defaced extension:
  33. FILE_NEW="${FILE_BASENAME//_defaced}"
  34. # remove the undefaced T1w file:
  35. rm -rf ${FILE_PARENT}/${FILE_NEW}
  36. echo "removed ${FILE_PARENT}/${FILE_NEW}"
  37. # replace the original T1w image with the defaced version:
  38. mv ${FILE} ${FILE_PARENT}/${FILE_NEW}
  39. echo "replaced with ${FILE}"
  40. done