使用python的pydicom模块对DICOMDIR文件的读取与结果显示

一、DICOMDIR 文件结构

DICOMDIR 文件是一个可变长度的迷你database文件,描述的是一个 4 层的树状结构。

1. Patient

2. Study

3. Series

4. Image

二、DICOM图像三种常见的存储形式

1. 单独存储:

只有一张单张的医学图像,没有任何其他的文件。

2. 混合存储 :

较常见,一份文件中包含多个病人和多个序列的图像,带有配套的DICOMDIR文件,但多个病人和多个序列的图像混在一起存放,较难分辨哪些图片属于同一个病人。

3. 分层存储 :

较常见,一份文件中包含多个病人和多个序列的图像,带有配套的DICOMDIR文件,但图片按照一定规律分层存放,可以分辨哪些图片属于同一个病人。

三、python的pydicom模块对DICOMDIR的操作

唯一需要修改的地方是第6行path = ‘ ’中填写DICOMDIR文件的地址,如C:\DICOMDIR

from os.path import dirname, join
from pprint import pprint
import pydicom
from pydicom.filereader import read_dicomdir

path = ‘ ’
#load the data 
dicom_dir = read_dicomdir(path)
base_dir = dirname(path)

#go through the patient record and print information
for patient_record in dicom_dir.patient_records:
    if (hasattr(patient_record, 'PatientID') and
            hasattr(patient_record, 'PatientName')):
        print("Patient: {}: {}".format(patient_record.PatientID,
                                       patient_record.PatientName))
    studies = patient_record.children
    # got through each serie
    for study in studies:
        print(" " * 4 + "Study {}: {}: {}".format(study.StudyID,
                                                  study.StudyDate,
                                                  study.StudyDescription))
        all_series = study.children
        # go through each serie
        for series in all_series:
            image_count = len(series.children)
            plural = ('', 's')[image_count > 1]

            # Write basic series info and image count

            # Put N/A in if no Series Description
            if 'SeriesDescription' not in series:
                series.SeriesDescription = "N/A"
            print(" " * 8 + "Series {}: {}: {} ({} image{})".format(
                series.SeriesNumber, series.Modality, series.SeriesDescription,
                image_count, plural))

            # Open and read something from each image, for demonstration
            # purposes. For simple quick overview of DICOMDIR, leave the
            # following out
            print(" " * 12 + "Reading images...")
            image_records = series.children
            image_filenames = [join(base_dir, *image_rec.ReferencedFileID)
                               for image_rec in image_records]

            datasets = [pydicom.dcmread(image_filename)
                        for image_filename in image_filenames]

            patient_names = set(ds.PatientName for ds in datasets)
            patient_IDs = set(ds.PatientID for ds in datasets)

            # List the image filenames
            print("\n" + " " * 12 + "Image filenames:")
            print(" " * 12, end=' ')
            pprint(image_filenames, indent=12)

            # Expect all images to have same patient name, id
            # Show the set of all names, IDs found (should each have one)
            print(" " * 12 + "Patient Names in images..: {}".format(
                patient_names))
            print(" " * 12 + "Patient IDs in images..: {}".format(
                patient_IDs))

结果类似

Patient: 77654033: Doe^Archibald
    Study 1: 20010101: XR C Spine Comp Min 4 Views
        Series 1: CR: N/A (1 image)
            Reading images...

            Image filenames:
             [           '/home/circleci/project/pydicom/data/test_files/dicomdirtests/77654033/CR1/6154']
            Patient Names in images..: {'Doe^Archibald'}
            Patient IDs in images..: {'77654033'}
        Series 2: CR: N/A (1 image)
            Reading images...

            Image filenames:
             [           '/home/circleci/project/pydicom/data/test_files/dicomdirtests/77654033/CR2/6247']
            Patient Names in images..: {'Doe^Archibald'}
            Patient IDs in images..: {'77654033'}
    Study 2: 19950903: CT, HEAD/BRAIN WO CONTRAST
        Series 1: CT: N/A (4 images)
            Reading images...

            Image filenames:
             [           '/home/circleci/project/pydicom/data/test_files/dicomdirtests/77654033/CT2/17106',
            '/home/circleci/project/pydicom/data/test_files/dicomdirtests/77654033/CT2/17136',
            '/home/circleci/project/pydicom/data/test_files/dicomdirtests/77654033/CT2/17166',
            '/home/circleci/project/pydicom/data/test_files/dicomdirtests/77654033/CT2/17196']
            Patient Names in images..: {'Doe^Archibald'}
            Patient IDs in images..: {'77654033'}
Patient: 98890234: Doe^Peter
    Study 1: 20010101:
        Series 1: CT: N/A (2 images)
            Reading images...

            Image filenames:
             [           '/home/circleci/project/pydicom/data/test_files/dicomdirtests/98892001/CT2N/6293',
            '/home/circleci/project/pydicom/data/test_files/dicomdirtests/98892001/CT2N/6924']
            Patient Names in images..: {'Doe^Peter'}
            Patient IDs in images..: {'98890234'}
      
    Study 2: 20030505: Brain
        Series 1: MR: N/A (1 image)
            Reading images...

            Image filenames:
             [           '/home/circleci/project/pydicom/data/test_files/dicomdirtests/98892003/MR1/4919']
            Patient Names in images..: {'Doe^Peter'}
            Patient IDs in images..: {'98890234'}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dr_yingli

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值