使用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_dicomdirpath = ‘ ’
#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') andhasattr(patient_record, 'PatientName')):print("Patient: {}: {}".format(patient_record.PatientID,patient_record.PatientName))studies = patient_record.children# got through each seriefor study in studies:print(" " * 4 + "Study {}: {}: {}".format(study.StudyID,study.StudyDate,study.StudyDescription))all_series = study.children# go through each seriefor 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 Descriptionif '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 outprint(" " * 12 + "Reading images...")image_records = series.childrenimage_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 filenamesprint("\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^ArchibaldStudy 1: 20010101: XR C Spine Comp Min 4 ViewsSeries 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 CONTRASTSeries 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^PeterStudy 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: BrainSeries 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'}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部