Reputation: 23
I want to add Dicom tags to a series of Dicom images and want to save that modified batch.
I have written a simple python script using pydicom which can edit and add dicom tags in a single Dicom image, but i want to do same procedure for complete image set (say 20 or 30 images). can anybody suggest me a way to do such task using pydicom or python?
Upvotes: 2
Views: 1728
Reputation: 2452
Let's suppose you have a list of dicom image file paths in an array named dicom_paths
. Then:
import pydicom
dicom_paths = [ list of image paths here ]
dicom_data = [pydicom.read_file(s) for s in dicom_paths]
for dicom_data_item in dicom_data:
#do what you want here
Hope it helps
Upvotes: 1
Reputation: 2041
Just collect your filenames in a list and process each filename (read the file, edit contents, save as new or maybe use the same name).
Have a look at the os
module from python. For instance, os.listdir('path')
returns a list of filenames found in the given path. If that path points to a directory that contains only dicom images you now have a list of dicom filenames. Next use os.path.join('path', filename)
to get an absolute path that you can use as input for reading a dicom file with pydicom.
Also you might want to use a for
loop.
Upvotes: 1