新聞中心
用python加載DICOM圖片的方法:使用pydicom、CV2、numpy、matplotlib等庫即可。pydicom庫是專門用來處理dicom圖像的python專用庫。

創(chuàng)新互聯(lián)建站服務(wù)項(xiàng)目包括黃島網(wǎng)站建設(shè)、黃島網(wǎng)站制作、黃島網(wǎng)頁制作以及黃島網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,黃島網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到黃島省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
python讀取DICOM圖像,需要以下幾個庫:pydicom、CV2、numpy、matplotlib。pydicom是專門處理dicom圖像的python專用包,numpy高效處理科學(xué)計算的包,依據(jù)數(shù)據(jù)繪圖的庫。
(推薦教程:Python入門教程)
安裝需要的庫
pip install matplotlib
pip install opencv-python
pip install pydicom pip install 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圖像里,包含了患者的相關(guān)信息的字典,我們可以通過dir查看DICOM文件有什么信息,可以通過字典返回相關(guān)的值。
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 新聞名稱:創(chuàng)新互聯(lián)Python教程:怎樣用python加載dicom圖片
網(wǎng)頁網(wǎng)址:http://fisionsoft.com.cn/article/cdcshsp.html


咨詢
建站咨詢
