本文摘自php中文网,作者巴扎黑,侵删。
DICOM3.0图像,由医学影像设备产生标准医学影像图像,DICOM被广泛应用于放射医疗,心血管成像以及放射诊疗诊断设备(X射线,CT,核磁共振,超声等),并且在眼科和牙科等其它医学领域得到越来越深入广泛的应用。在数以万计的在用医学成像设备中,DICOM是部署最为广泛的医疗信息标准之一。当前大约有百亿级符合DICOM标准的医学图像用于临床使用。 看似神秘的图像文件,究竟是如何读取呢?网上随便 一搜,都有很多方法,但缺乏比较系统的使用方法,下文综合百度资料,结合python2.7,讲解如何读取及使用DICOM图像。
读取DICOM图像,需要以下几个库:pydicom、CV2、numpy、matplotlib。pydicom专门处理dicom图像的python专用包,numpy高效处理科学计算的包,依据数据绘图的库。
安装:
1 2 | pip install opencv-python #opencv的安装,小度上基本都是要下载包,安装包后把包复制到某个文件夹下,
#后来我在找到这种pip的安装方法,亲测可用
|
如果没有记错,安装pydicom时,也会自动把numpy安装上。
安装好这些库后,就可以对dicom文件操作。具体看下面代码:
1 | 1 #-*-coding:utf-8-*- 2 import cv2 3 import numpy 4 import dicom 5 from matplotlib import pyplot as plt 6 7 dcm = dicom.read_file( "AT0001_100225002.DCM" ) 8 dcm.image = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept 9 10 slices = []11 slices.append(dcm)12 img = slices[ int(len(slices)/2) ].image. copy ()13 ret,img = cv2.threshold(img, 90,3071, cv2.THRESH_BINARY)14 img = numpy.uint8(img)15 16 im2, contours, _ = cv2.findContours(img,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)17 mask = numpy.zeros(img.shape, numpy.uint8)18 for contour in contours:19 cv2.fillPoly(mask, [contour], 255)20 img[(mask > 0)] = 25521 22 23 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2,2))24 img = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)25 26 27 img2 = slices[ int(len(slices)/2) ].image. copy ()28 img2[(img == 0)] = -200029 30 31 plt.figure(figsize=(12, 12))32 plt.subplot(131)33 plt.imshow(slices[int(len(slices) / 2)].image, 'gray' )34 plt.title( 'Original' )35 plt.subplot(132)36 plt.imshow(img, 'gray' )37 plt.title( 'Mask' )38 plt.subplot(133)39 plt.imshow(img2, 'gray' )40 plt.title( 'Result' )41 plt.show()
|
在DICOM图像里,包含了患者的相关信息的字典,我们可以通过dir查看DICOM文件有什么信息,可以通过字典返回相关的值。
1 | 1 import dicom 2 import json 3 def loadFileInformation(filename): 4 information = {} 5 ds = dicom.read_file(filename) 6 information[ 'PatientID' ] = ds.PatientID 7 information[ 'PatientName' ] = ds.PatientName 8 information[ 'PatientBirthDate' ] = ds.PatientBirthDate 9 information[ 'PatientSex' ] = ds.PatientSex10 information[ 'StudyID' ] = ds.StudyID11 information[ 'StudyDate' ] = ds.StudyDate12 information[ 'StudyTime' ] = ds.StudyTime13 information[ 'InstitutionName' ] = ds.InstitutionName14 information[ 'Manufacturer' ] = ds.Manufacturer15 print dir(ds)16 print type(information)17 return information18 19 a=loadFileInformation( 'AT0001_100225002.DCM' )20 print a
|
以上就是python--DICOM图像的研究的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python怎么批量合并excel表格
Python数据分析怎么学
如何调试Python代码
在 flask 中集成 vue
Python怎么画矩形
Python如何输出换行
Python内置的集成开发工具是什么
Python 的自省是什么?
Python面向对象之访问限制
Python基础教程之with、contextlib的实例用法详解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python--DICOM图像的研究