介绍
这篇文章将为大家详细讲解有关如何使用python读取dicom文件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
目标:利用python读取dicom文件,并进行处理生成信息。txt和原始文件
实现:通过pydicom读取dicom文件
<强>代码:强>
import numpy import pydicom import 操作系统 #,并建置文件所在的文件夹目录 时间=PathDicom & # 39;/home/路/testdata 1.3.6.1.4.1.9328.50.1.42697596859477567872763647333745089432/& # 39; #,筛选出文件夹目录下所有的dicom文件 时间=lstFilesDCM [] for 目录名,subdirList, fileList 拷贝os.walk (PathDicom): for 才能;filename 拷贝文件列表: ,,,if & # 39; .dcm& # 39;,拷贝filename.lower (): ,,,,,lstFilesDCM.append (os.path.join(目录名,文件名)) #,Get ref 文件 时间=RefDs pydicom.read_file (lstFilesDCM [0]) #,Load dimensions  based 提醒,number of 行,列,以及slices (along 从而,Z 轴) ConstPixelDims =, (int (RefDs.Rows), int (RefDs.Columns), len (lstFilesDCM)) #,Load spacing  values (毫米)拷贝 ConstPixelSpacing =,(浮动(RefDs.PixelSpacing[0]),,浮子(RefDs.PixelSpacing[1]),,浮子(RefDs.SliceThickness)) ,#,节省info.txt 时间=info ConstPixelDims + ConstPixelSpacing 时间=f 开放(& # 39;/home/路/testdata 1.3.6.1.4.1.9328.50.1.42697596859477567872763647333745089432/info.txt& # 39;,, & # 39; w # 39;) for n 拷贝信息: f.write才能(str (n) + & # 39;, & # 39;) f.close () #,According 用位置排序 位置=,[] for 小姐:拷贝范围(len (lstFilesDCM)): 时间=ds 才能;pydicom.read_file (lstFilesDCM[我]) location.append才能(ds.SliceLocation) location.sort () #,从而array is  sized based 提醒& # 39;ConstPixelDims& # 39; 时间=ArrayDicom numpy.zeros (len (lstFilesDCM), RefDs.Rows,, RefDs.Columns),, dtype=RefDs.pixel_array.dtype) #,loop through  all 从而DICOM 文件 for filenameDCM  lstFilesDCM拷贝: #,才能read 从而文件 时间=ds 才能;pydicom.read_file (filenameDCM) #,才能store 从而raw image 数据 ArrayDicom才能[location.index (ds.SliceLocation),,,,,:],=ds.pixel_array ,#,节省原材料 时间=ds ArrayDicom.tostring () 时间=f 开放(& # 39;/home/路/testdata/1.3.6.1.4.1.9328.50.1.42697596859477567872763647333745089432/1.raw& # 39;,, & # 39; wb # 39;) f.write (ds) f.close ()
<强>代码编写过程遇到的问题及解决方法:强>
<强>问题> python有哪些常用库
python常用的库:1. requesuts; 2. scrapy; 3.枕头;4.扭曲;5. numpy; 6. matplotlib; 7. pygama; 8。ipyhton等。
关于如何使用python读取dicom文件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。