【问题标题】:How to edit nested/child DICOM tags for sequences using pyDicom?如何使用 pyDicom 编辑序列的嵌套/子 DICOM 标签?
【发布时间】:2022-01-08 06:44:49
【问题描述】:

我正在尝试使用 pyDicom 将 DICOM 数据集中包含的所有 TIME (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 的嵌套/子标签。

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

【问题讨论】:

    标签: dicom pydicom


    【解决方案1】:

    walk method 与回调一起使用可能是最简单的方法。您可以将source code for remove_private_tags() 视为示例,但您的函数将检查“TM”的VR 并作用于这些数据元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 2021-10-04
      • 1970-01-01
      • 2020-02-19
      • 2012-12-29
      • 1970-01-01
      相关资源
      最近更新 更多