tags - pydicom: Add Series Desrcription to DICOMDIR - Stack Overflow

admin2025-04-21  1

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

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

Share Improve this question edited Feb 12 at 9:53 HackJack asked Feb 11 at 12:37 HackJackHackJack 34 bronze badges 2
  • 1 Hi and welcome! Please provide a minimal reproducible example of what you have so far. – jeannej 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. – MrBean Bremen Commented Feb 12 at 14:28
Add a comment  | 

2 Answers 2

Reset to default 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.

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
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745211694a290608.html

最新回复(0)