0

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

2
  • 1
    Hi and welcome! Please provide a minimal reproducible example of what you have so far. Commented Feb 11 at 14:28
  • SeriesDescription is not in the list of allowed additional tags in a DICOMDIR, so a viewer will probably not show it even if added. Commented Feb 12 at 14:28

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Two Changes in fileset.py work as expected!

def _define_myseries(ds: Dataset) -> Dataset:
    """Return a SERIES directory record from `ds`."""
    #modification of _define_series; bgt 2025/02/17
    _check_dataset(ds, ["Modality",
                        "SeriesInstanceUID",
                        "SeriesNumber",
                        "SeriesDescription"])

    record = Dataset()
    record.Modality = ds.Modality
    record.SeriesInstanceUID = ds.SeriesInstanceUID
    record.SeriesNumber = ds.SeriesNumber
    record.SeriesDescription = ds.SeriesDescription

    return record

Updated the DIRECTORY_RECORDRS dictionary "SERIES" entry.

    "SERIES": _define_myseries,  # INTERMEDIATE

2 Comments

You shouldn't need to modify fileset.py itself, the DIRECTORY_RECORDERS dict can imported and modified by your code.
@scaramallion Yes you are right. Thank you for this hint. It also works fine without any adjustments in the original fileset.py and I don't run into trouble using this in other environments where changes weren't made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.