您的位置:首页 > 编程语言 > Python开发

python2.7对DICOM图像的读取

2017-10-26 12:50 465 查看
DICOM介绍

DICOM(Digital Imaging and Communications in Medicine)即医学数字成像和通信,是医学图像和相关信息的国际标准(ISO 12052)。

DICOM标准中涵盖了医学数字图像的采集、归档、通信、显示及查询等几乎所有信息交换的协议;以开放互联的架构和面向对象的方法定义了一套包含各种类型的医学诊断图像及其相关的分析、报告等信息的对象集;定义了用于信息传递、交换的服务类与命令集,以及消息的标准响应;详述了标识各类信息对象的技术;提供了应用于网络环境(OSI或TCP/IP)的服务支持;结构化地定义了制造厂商的兼容性声明(Conformance
Statement)。

前期准备工作

首先将所需包安装好:pydicom、CV2、numpy、matplotlib、pydicom
pip install matplotlib
pip install pydicom
pip install opencv-python

其中,opencv-python包安装结束显示如下图:



读取DICOM图片

显示图片:
#-*-coding:utf-8-*-
import cv2
import numpy
import dicom
from matplotlib import pyplot as plt

dcm = dicom.read_file("000001.dcm")
dcm.image = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept

slices = []
slices.append(dcm)
img = slices[ int(len(slices)/2) ].image.copy()
ret,img = cv2.threshold(img, 90,3071, cv2.THRESH_BINARY)
img = numpy.uint8(img)

im2, contours, _ = cv2.findContours(img,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
mask = numpy.zeros(img.shape, numpy.uint8)
for contour in contours:
cv2.fillPoly(mask, [contour], 255)
img[(mask > 0)] = 255

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2,2))
img = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)

img2 = slices[ int(len(slices)/2) ].image.copy()
img2[(img == 0)] = -2000

plt.figure(figsize=(12, 12))
plt.subplot(131)
plt.imshow(slices[int(len(slices) / 2)].image, 'gray')
plt.title('Original')
plt.subplot(132)
plt.imshow(img, 'gray')
plt.title('Mask')
plt.subplot(133)
plt.imshow(img2, 'gray')
plt.title('Result')
plt.show()


图片显示效果如下:



查看患者信息字典:

import dicom
import json
def loadFileInformation(filename):
information = {}
ds = dicom.read_file(filename)
information['PatientID'] = ds.PatientID
information['PatientName'] = ds.PatientName
information['PatientBirthDate'] = ds.PatientBirthDate
information['PatientSex'] = ds.PatientSex
information['StudyID'] = ds.StudyID
information['StudyDate'] = ds.StudyDate
information['StudyTime'] = ds.StudyTime
information['Manufacturer'] = ds.Manufacturer
print dir(ds)
print type(information)
return information

a=loadFileInformation('000001.dcm')
print a


内容显示如下:



可见,[]中显示所有信息项目;<>中显示信息类型,此处为字典类型;{}中即为你所指定的打印类型,有部分项目为空。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  图片 python