新聞中心
這篇文章運(yùn)用簡(jiǎn)單易懂的例子給大家介紹python加載dicom圖片怎么實(shí)現(xiàn),代碼非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
成都創(chuàng)新互聯(lián)長(zhǎng)期為上千多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為楊浦企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,楊浦網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
用python加載dicom圖片的方法:使用pydicom、CV2、numpy、matplotlib等庫(kù)即可。pydicom庫(kù)是專門用來(lái)處理dicom圖像的python專用庫(kù)。
python讀取DICOM圖像,需要以下幾個(gè)庫(kù):pydicom、CV2、numpy、matplotlib。pydicom是專門處理dicom圖像的python專用包,numpy高效處理科學(xué)計(jì)算的包,依據(jù)數(shù)據(jù)繪圖的庫(kù)。
安裝需要的庫(kù)
pip install matplotlib
pip install opencv-python
pip install pydicom pip install numpy
安裝好這些庫(kù)后就可以對(duì)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)信息的字典,我們可以通過(guò)dir查看DICOM文件有什么信息,可以通過(guò)字典返回相關(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
關(guān)于python加載dicom圖片怎么實(shí)現(xiàn)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
網(wǎng)站欄目:python加載dicom圖片怎么實(shí)現(xiàn)
文章出自:http://www.dlmjj.cn/article/psdces.html