如何使用 pyDicom 编辑序列的 nested/child DICOM 标签?

How to edit nested/child DICOM tags for sequences using pyDicom?

我正在尝试使用 pyDicom 将 DICOM 数据集中包含的所有时间 (VR = TM) 标签设置为占位符值。

我可以删除 DICOM 元数据的 root 中的所有 TIME (VR = TM) 标签的值:

TIME_TAGS = [
    (0x10, 0x32),  # Patient's Birth Time
    (0x40, 0x245),  # Performed Procedure Step Start Time
    (0x8, 0x13),  # Instance Creation Time
    (0x8, 0x30),  # Study Time
    (0x8, 0x31),  # Series Time
    (0x8, 0x32),  # Acquisition Time
    (0x8, 0x33),  # Content Time
]
TIME_VAL_REPLACEMENT = '120000'


def _clear_times(dir_name: str) -> None:
    '''
    Set all DICOM standard (i.e. non-vendor) time tags
    to a non-unique value (defined in _presets.py)

    dir_name:
        full path of the directory to process
    '''
    for dcm_file in os.listdir(dir_name):
        dcm_file = os.path.join(dir_name, dcm_file)
        # _presets defines what time tags to change
        for time_str in TIME_TAGS:
            dcmfile = pydicom.dcmread(dcm_file)
            if dcmfile.get(time_str, None) and dcmfile.get(time_str,
                                                           None).VR == 'TM':
                logging.debug("Removing time (%s)", time_str)
                new_data = pydicom.dataelem.DataElement(
                    time_str, 'TM', TIME_VAL_REPLACEMENT)
                dcmfile[time_str] = new_data
                dcmfile.save_as(dcm_file)
            else:
                logging.debug("%s not set", time_str)

但是,这遗漏了 sequences 的 nested/child 个标签。

使用 pyDicom 删除所有相关 nested/child 标签的最佳方法是什么?

walk method with a callback is probably the easiest way to do this. You could see the source code for remove_private_tags() 为例,但您的函数将检查 'TM' 的 VR 并对这些数据元素采取行动。