import os import pydicom import numpy as np import matplotlib.pyplot as plt

打开DICOM文件

filename = 'C:\Users\lenovo\Desktop\数据结构与算法C++\20084125-张亭-数据结构算法实验1\dicom\Dicomread\11.dcm' ds = pydicom.dcmread(filename)

判断文件是否为DICOM格式

if ds.file_meta.MediaStorageSOPClassUID != '1.2.840.10008.5.1.4.1.1.2': print('Not a DICOM file!') exit()

获取基本信息

file_name = os.path.basename(filename) file_path = os.path.dirname(filename) file_size = os.path.getsize(filename)

获取患者信息

patient_id = ds.PatientID patient_name = ds.PatientName patient_sex = ds.PatientSex patient_age = ds.PatientAge

获取检查信息

study_id = ds.StudyID study_date = ds.StudyDate study_time = ds.StudyTime study_type = ds.Modality

获取图像信息

pixel_data = ds.pixel_array pixel_size = (ds.PixelSpacing[0], ds.PixelSpacing[1]) pixel_spacing = (ds.SliceThickness, ds.PixelSpacing[0], ds.PixelSpacing[1]) image_position = ds.ImagePositionPatient image_orientation = ds.ImageOrientationPatient

获取序列信息

sequence_number = ds.InstanceNumber sequence_description = ds.SeriesDescription sequence_type = ds.Modality sequence_uid = ds.SeriesInstanceUID

输出结果

print('File name: %s' % file_name) print('File path: %s' % file_path) print('File size: %s bytes' % file_size) print('Patient ID: %s' % patient_id) print('Patient name: %s' % patient_name) print('Patient sex: %s' % patient_sex) print('Patient age: %s' % patient_age) print('Study ID: %s' % study_id) print('Study date: %s' % study_date) print('Study time: %s' % study_time) print('Study type: %s' % study_type) print('Pixel data: %s' % pixel_data) print('Pixel size: %s' % str(pixel_size)) print('Pixel spacing: %s' % str(pixel_spacing)) print('Image position: %s' % str(image_position)) print('Image orientation: %s' % str(image_orientation)) print('Sequence number: %s' % sequence_number) print('Sequence description: %s' % sequence_description) print('Sequence type: %s' % sequence_type) print('Sequence UID: %s' % sequence_uid)

Python DICOM 文件解析与信息提取

原文地址: https://www.cveoy.top/t/topic/ncnd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录