python读取Dicom文件的示例详解
更新时间:2024年01月18日 15:08:57 作者:北方骑马的萝卜
这篇文章通过示例代码介绍了python读取Dicom文件的方法,代码简单易懂,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
1. pydicom Library
import pydicom # Read DICOM file dataset = pydicom.dcmread("path_to_dicom_file.dcm") # Access metadata and pixel data patient_name = dataset.PatientName pixel_array = dataset.pixel_array
2. SimpleITK Library
import SimpleITK as sitk # Read DICOM file image = sitk.ReadImage("path_to_dicom_file.dcm") # Access metadata and pixel data spacing = image.GetSpacing() pixel_array = sitk.GetArrayFromImage(image)
3. ITK Library (Insight Toolkit)
import itk # Read DICOM series series_reader = itk.ImageSeriesReader.New() series_reader.SetFileNames("path_to_dicom_series/*.dcm") series_reader.Update() # Access metadata and pixel data image = series_reader.GetOutput() spacing = image.GetSpacing() pixel_array = itk.GetArrayViewFromImage(image)
4. GDCM Library (Grassroots DICOM)
import gdcm # Read DICOM file file_reader = gdcm.ImageReader() file_reader.SetFileName("path_to_dicom_file.dcm") file_reader.Read() # Access metadata and pixel data dataset = file_reader.GetImage() pixel_array = dataset.GetBuffer() import gdcm # Read DICOM file file_reader = gdcm.ImageReader() file_reader.SetFileName("path_to_dicom_file.dcm") file_reader.Read() # Access metadata and pixel data dataset = file_reader.GetImage() pixel_array = dataset.GetBuffer()
import os import SimpleITK as sitk import numpy as np # Specify the folder containing DICOM files folder_path = "path_to_folder_containing_dicom_files" # Get the list of DICOM files in the folder dicom_files = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith('.dcm')] # Read the DICOM series reader = sitk.ImageSeriesReader() reader.SetFileNames(dicom_files) image = reader.Execute() # Convert the 3D image to a NumPy array volume = sitk.GetArrayFromImage(image) # Access metadata (same for all DICOM files in the folder) first_file = dicom_files[0] first_dataset = sitk.ReadImage(first_file) patient_name = first_dataset.GetMetaData("PatientName")
到此这篇关于python读取Dicom文件的文章就介绍到这了,更多相关python读取Dicom文件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
win10安装tesserocr配置 Python使用tesserocr识别字母数字验证码
这篇文章主要介绍了win10安装tesserocr配置 Python使用tesserocr识别字母数字验证码,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下2020-01-01
最新评论