I want to rearrange non medical DICOM-data. Using pydicom
I want to produce a DICOMDIR with at least one additional tag. For each Series
I want to add the Series Description
like this:
(0008, 103e) Series Description LO: '7253 1mm'
This should enable a DICOM-Viewer to show this information in the treeview as a series-label.
Are there any hints how to do this for each series? I cannot find an exhaustive explanation in the pydicom
documentation.
That's how I collect the dcm-files and write a DICOMDIR:
from os.path import isdir, join
from pydicom.fileset import FileSet
path2dcm = r"D:\my\path\to\dcm-files"
instanceList =[]
def ListFolderEntries (path):
for entry in listdir(path):
npath = (join(path,entry))
if isdir(npath):
ListFolderEntries(npath)
else:
instanceList.append(npath)
#walk through folders recursively
ListFolderEntries (path2dcm)
for Inst in instanceList:
myFS.add(Inst)
#Here perhaps add the series Desicription?
myFS.write() #creates the file structure and a DICOMDIR
Thanks
As it says in pydicom's File-set tutorial (which covers DICOMDIR), you can write your own SERIES record function to include Series Description then update the pydicom.fileset.DIRECTORY_RECORDERS dict to use your new function instead of the default (found here).
from pydicom import Dataset
from pydicom.fileset import DIRECTORY_RECORDERS
def my_series_record(ds: Dataset) -> Dataset:
# `ds` is the SOP Instance you're creating a record for
record = Dataset()
# See the original series record function
# for the required elements
if "SeriesDescription" in ds:
record.SeriesDescription = ds.SeriesDescription
return record
DIRECTORY_RECORDERS["SERIES"] = my_series_record
You can then add new SOP Instances to the File-set as normal and the SERIES records will include Series Description. However, as @mrbean-bremen said, Series Description is not part of the requirements for a SERIES record so viewers may not display it.