pydicom / deid

best effort anonymization for medical images using python
https://pydicom.github.io/deid/
MIT License
140 stars 43 forks source link

Preserving initial folder structure #170

Closed jkarten95 closed 3 years ago

jkarten95 commented 3 years ago

Hi All,

In reading the documentation, I see that I can output a newly de-identified .dcm file to a specified folder. I was wondering if there is a way to de-identify "in place" instead of sending to a new folder and thereby preserving the original folder structure? I ask because the imaging studies are kept in complex folder structures that we'd like to maintain. Thanks for any advice!

Jordan

vsoch commented 3 years ago

Could you show me the exact command you are running so I can take a look? There are several ways to interact with deid and I want to make sure we are discussing the same one.

jkarten95 commented 3 years ago

Sure!

base = '/folder/with/original/study/directories'
dicom_files = list(get_files(base))

#other code

cleaned_files = replace_identifiers(dicom_files=dicom_files, deid=recipe, ids=items, save=True, overwrite=True, 
output_folder='/folder/for/new/files'). 

I am wondering if instead of stripping the .dcm files from the original location, can they be saved in their original folders? Essentially I have multiple imaging studies in one directory.

vsoch commented 3 years ago

@jkarten95 did you try setting the same output folder as where you already have the files, and then overwrite to True?

vsoch commented 3 years ago

Actually scratch that - just leave the output folder as None and set overwrite to true. See here: https://github.com/pydicom/deid/blob/7e7196dcc21bb489b1fecf32fb5b0c0420146b3f/deid/dicom/utils.py#L97

vsoch commented 3 years ago

Based on reading the code, that should accomplish what you want (let me know if it does not!)

jkarten95 commented 3 years ago

That worked perfectly! Thanks for the help.

vsoch commented 3 years ago

Definitely! Happy to do so :)