How to make a workflow Python under Windows

91 views
Skip to first unread message

David Roy

unread,
Feb 9, 2015, 10:11:31 AM2/9/15
to dicombrow...@googlegroups.com
Hello,

I would like to create a workflow to anonymize several batches of images at once, and send them
to a research PACS.

I also need to modify the patient's ID to remove the initials and only keep the number.

All this needs to work under Windows (to be used in a hospital).

I'm familiar with Python scripting, but less with DicomBrowser. Please, could you provide me
with some clues to get started.


Thanks
David (postdoc Montréal)



Kevin Archie

unread,
Feb 9, 2015, 10:51:25 AM2/9/15
to dicombrow...@googlegroups.com
Hi, David,

If I understand what you’re looking for, this is easy to do in DicomBrowser, or, more properly, DicomRemap: http://nrg.wustl.edu/software/dicom-browser/instructions/command-line-interface/ , which is the command-line interface to the DicomEdit language that DicomBrowser also uses. Most likely you can wrap it up with a Python (or sh) one-liner.

Roughly: you write a DicomEdit script that does what you need, then point DicomRemap to the top-level directory of your DICOM data, telling it which script to use and where to send the output.

The best DicomEdit documentation is here: http://nrg.wustl.edu/software/dicomedit/dicomedit-reference/ . It’s correct but incomplete, which I hope to fix soon (no, really).

Writing the DicomEdit script might be the most challenging part of this, depending on how much anonymization you want to do. There are some long and complicated examples based on the Part 15 confidentiality profiles here: https://bitbucket.org/dicomedit/dicomedit/src/tip/src/main/dicomedit/ . That’s a good place to start if you expect to need a thorough scrubbing, whereas if you have just a few fields you need to clean up, you’re better off writing a small one from scratch.

The one custom-ish part of what you’ve described would be the patient ID modification. Depending on how regular your IDs are, you might be able to get away with something as simple as:

(0010,0020) := substring[(0010,0020), 2, 7] // assumes IDs of form XY012345

If you need something more complicated, let me know details and I’ll either figure out how to do it or hack the language until it does what you need.

Now some bad news: DicomBrowser has been neglected over the last few years, and the installer you’d get from nrg.wustl.edu gives you an old version that doesn’t include a lot of the newer DicomEdit features. You can get newer versions from ftp://ftp.nrg.wustl.edu/pub/DicomBrowser , but I don’t have a Windows installer of a recent build. The latest Windows installer is 1.7.0b1, which would still be better than 1.5.2 and would include the DicomEdit features needed to run the sample scripts I mentioned above. Even better would be one of the more recent .tgz builds, but I can’t promise that the .bat files there have been updated to work properly, so there might be some experimentation necessary. If you run into trouble, let me know.

It’s also possible, if all you need to change is that one field, that you’d be better off using pydicom or the DCMTK command-line tools surrounded by some scripting magic. DicomRemap wraps up all the things you need to do (walk the tree to find DICOM, modify, and do the C-STORE) but it’s a big dependency to pull in if it’s not working for you quickly. Obviously I’d prefer people to be using DicomEdit (and will be happy to help you through problems you run into) but other tools work well too.

Good luck, and please don’t hesitate to ask for help if you run into trouble.

 - Kevin

--
You received this message because you are subscribed to the Google Groups "DicomBrowser users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dicombrowser-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Roy

unread,
Feb 9, 2015, 5:08:12 PM2/9/15
to dicombrow...@googlegroups.com
Hi Kevin,

Thank you for these tips, I do appreciate.

I'll let you know if I need more help on that.

For now I just have another question on how to use your function match,
I already sent another post for that.


Best
David
To unsubscribe from this group and stop receiving emails from it, send an email to dicombrowser-users+unsub...@googlegroups.com.

Graham Warner

unread,
Jun 22, 2015, 2:13:38 PM6/22/15
to dicombrow...@googlegroups.com
Check out the command line interface (link provided in Kevin's answer) and use python's subprocess module to run the DicomBrowser code. Example from a script I'm working on:

import subprocess

bash_code
= '/space/jazz/1/users/gwarner/DicomBrowser-1.5.2/bin/DicomRemap -d ' + anon_dir + ' -o '+ save_dir + ' ' + dcm_dir

subprocess
.call(bash_code, shell=True)
Reply all
Reply to author
Forward
0 new messages