[英]How to load DICOM files in Python?
I am trying to figure out the basics of importing DICOM files in Python using pydicom. 我试图弄清楚使用pydicom在Python中导入DICOM文件的基础。 While trying really simple code, I get following errors:
在尝试非常简单的代码时,出现以下错误:
For code: import dicom 对于代码:import dicom
filePath="C:\Python34\Lib\site-packages\dicom\testfiles"
ds=dicom.read_file(filePath[0])
I get error: C:\\Python34\\python.exe C:/Users/041213/PycharmProjects/D/Deki.py Traceback (most recent call last): File "C:/Users/041213/PycharmProjects/D/Deki.py", line 4, in ds=dicom.read_file(filePath[0]) File "C:\\Python34\\lib\\site-packages\\dicom\\filereader.py", line 589, in read_file fp = open(fp, 'rb') FileNotFoundError: [Errno 2] No such file or directory: 'C' 我收到错误消息:C:\\ Python34 \\ python.exe C:/Users/041213/PycharmProjects/D/Deki.py回溯(最近一次调用最近):文件“ C:/Users/041213/PycharmProjects/D/Deki.py ”,在ds = dicom.read_file(filePath [0])文件中,第4行,在read_file的第589行中,文件“ C:\\ Python34 \\ lib \\ site-packages \\ dicom \\ filereader.py” fp = open(fp,'rb ')FileNotFoundError:[错误2]没有这样的文件或目录:'C'
I am using Python 3.4, pydicom 0.9.9 and JetBrains PyCharm Community Edition 2016.3.2 If anyone can help me with this, or even just help me how to load a DICOM file in general, I would appreciate it a lot. 我正在使用Python 3.4,pydicom 0.9.9和JetBrains PyCharm Community Edition 2016.3.2,如果有人可以帮助我,甚至只是帮助我如何一般地加载DICOM文件,我将不胜感激。
you're passing the first char of the string ( C
) instead of the full string. 您传递的是字符串(
C
)的第一个字符而不是完整的字符串。 Just do: 做就是了:
ds=dicom.read_file(filePath)
next error you'll stumble into: use raw prefix or \\t
gets interpreted as a tabulation character: 您会遇到的下一个错误:使用原始前缀或
\\t
被解释为制表符:
filePath=r"C:\Python34\Lib\site-packages\dicom\testfiles"
^
Use and \\ escape character to avoid issues with tab and other special characters. 使用和\\转义字符可以避免制表符和其他特殊字符的问题。 Also remember when you do filePath[0] on a string it returns the first character
还记得当对字符串执行filePath [0]时,它返回第一个字符
filePath="C:\\Python34\\Lib\\site-packages\\dicom\\testfiles"
ds=dicom.read_file(filePath)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.