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
總結
#以上是關於python讀取DICOM影像的程式碼實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Dreamweaver CS6
視覺化網頁開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)