发布于 2017-10-22 10:53:41 | 300 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Python3 Cookbook中文版,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


DICOM(Digital Imaging and Communications in Medicine)即医学数字成像和通信,是医学图像和相关信息的国际标准(ISO 12052)。下面这篇文章主要给大家介绍了关于python对DICOM图像读取的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧。

DICOM介绍

DICOM3.0图像,由医学影像设备产生标准医学影像图像,DICOM被广泛应用于放射医疗,心血管成像以及放射诊疗诊断设备(X射线,CT,核磁共振,超声等),并且在眼科和牙科等其它医学领域得到越来越深入广泛的应用。在数以万计的在用医学成像设备中,DICOM是部署最为广泛的医疗信息标准之一。当前大约有百亿级符合DICOM标准的医学图像用于临床使用。

看似神秘的图像文件,究竟是如何读取呢?网上随便 一搜,都有很多方法,但缺乏比较系统的使用方法,下文综合百度资料,结合python2.7,讲解如何读取及使用DICOM图像。

读取DICOM图像,需要以下几个库:pydicom、CV2、numpy、matplotlib。pydicom专门处理dicom图像的python专用包,numpy高效处理科学计算的包,依据数据绘图的库。

安装:


pip install matplotlib

pip install opencv-python #opencv的安装,小度上基本都是要下载包,安装包后把包复制到某个文件夹下,
#后来我在https://pypi.python.org/pypi/opencv-python找到这种pip的安装方法,亲测可用

pip install pydicom

pip install numpy

如果没有记错,安装pydicom时,也会自动把numpy安装上。

安装好这些库后,就可以对dicom文件操作。

具体看下面代码:


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

dcm = dicom.read_file("AT0001_100225002.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()

在DICOM图像里,包含了患者的相关信息的字典,我们可以通过dir查看DICOM文件有什么信息,可以通过字典返回相关的值。


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['InstitutionName'] = ds.InstitutionName
 information['Manufacturer'] = ds.Manufacturer
 print dir(ds)
 print type(information)
 return information

a=loadFileInformation('AT0001_100225002.DCM')
print a

总结

以上就是这篇文章的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对PHPERZ的支持。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务