pydicom读取dicom文件报错
之前采用pydicom读取dicom文件一切都很正常,不过最近读取一批数据的时候,会报错
读取代码
file = pydicom.read_file(filepath)
data = file.pixel_array
问题就出在pixel_array这个属性上,报错如下
OSError Traceback (most recent call last)
c:\python35\lib\site-packages\pydicom\pixel_data_handlers\pillow_handler.py in get_pixeldata(dicom_dataset)
fio = io.BytesIO(pixel_data)
--> decompressed_image = Image.open(fio)
except IOError as e: c:\python35\lib\site-packages\PIL\Image.py in open(fp, mode)
raise IOError("cannot identify image file %r"
-> % (filename if filename else fp)) OSError: cannot identify image file <_io.BytesIO object at 0x000002418FC85CA8> During handling of the above exception, another exception occurred: NotImplementedError Traceback (most recent call last)
<ipython-input--c00f3f09682d> in <module>()
----> file.pixel_array c:\python35\lib\site-packages\pydicom\dataset.py in pixel_array(self)
The Pixel Data (7FE0,) as a NumPy ndarray.
"""
--> self.convert_pixel_data()
return self._pixel_array c:\python35\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self)
) --> raise last_exception def decompress(self): c:\python35\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self)
try:
# Use the handler to get a 1D numpy array of the pixel data
--> arr = handler.get_pixeldata(self)
self._pixel_array = reshape_pixel_array(self, arr) c:\python35\lib\site-packages\pydicom\pixel_data_handlers\pillow_handler.py in get_pixeldata(dicom_dataset)
decompressed_image = Image.open(fio)
except IOError as e:
--> raise NotImplementedError(e.strerror)
UncompressedPixelData.extend(decompressed_image.tobytes())
except Exception: NotImplementedError: None
看到一篇博客https://blog.csdn.net/inter_peng/article/details/74370306与我的问题类似,都出在dicom文件格式上面,这种压缩格式用pydicom读取不出来,采用SimpleITK可以解决
file = sitk.ReadImage(filepath)
data = sitk.GetArrayFromImage(file)
pydicom读取dicom文件报错的更多相关文章
- python3 读取dbf文件报错 UnicodeDecodeError: 'gbk' codec can't decode
在读取dbf文件时由于编码问题报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 49: incomplete ...
- 解决Requests中文乱码【有用】,读取htm文件 读取txt文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0
打开这个网址https://blog.csdn.net/chaowanghn/article/details/54889835 python在open读取txt文件时,出现UnicodeDecodeE ...
- python中读取json文件报错,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’
利用python中的json读取json文件时,因为错误使用了相应的方法导致报错:TypeError:the Json object must be str, bytes or bytearray,n ...
- 【Python】读取cvs文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6: invalid start byte
现在有文件data.csv 文件编码格式为:ANSI data.csv 1|1|1|北京市 2|1|2|天津市 3|1|3|上海市 4|1|4|重庆市 5|1|5|石家庄市 6|2|5|唐山市 7|3 ...
- 读取xml文件报错:Invalid byte 2 of 2-byte UTF-8 sequence。
程序读取xml文件后,系统报“Invalid byte 2 of 2-byte UTF-8 sequence”错误,如何解决呢? 1.程序解析xml的时候,出现Invalid byte 2 of 2- ...
- python读取xml文件报错ValueError: multi-byte encodings are not supported
1.在使用python对xml文件进行读取时,提示ValueError: multi-byte encodings are not supported 很多贴子上说把xml的编码格式改为,就可以正常执 ...
- .net 读取Excel文件报错
错误内容 Microsoft Office Excel 不能访问文件“D:\WWWRoot\Website\Test\Excels\Test1.xls”. 可能的原因有: 1 文件名称或路径不存在. ...
- [解决问题] pandas读取csv文件报错OSError解决方案
python用padans.csv_read函数出现OSError: Initializing from file failed 问题:文件路径中存在中文 解决办法:修改文件路径名为全英文包括文件名
- python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)
python 读取csv文件报错问题 import csv with open('E:/Selenium2script/DDT模块/test.csv','rb') as f: readers = cs ...
随机推荐
- eclipse导入web项目报错 Cannot find the class file for javax.servlet.ServletContext.
当eclipse中新导入的Java Project的时候,往往会碰到各种各样的问题,下面是个典型的问题: Cannot find the class file for javax.servlet.Se ...
- Zedboard学习(一):移植Ubuntu桌面操作系统 标签: ubuntu移植zedboardFPGA 2017-07-04 21:53 26人阅读
环境准备: 首先,需要的肯定是Ubuntu操作系统.可以在自己的电脑上安装物理机,也可以是虚拟机下运行的.我的是在Vmware下运行的Ubuntu14.04 32位操作系统. 由于zedboard上的 ...
- 约瑟夫问题的变种 LA3882
题目大意: N个数排成一圈,第一次删除m,以后每k个数删除一次,求最后一被删除的数. 如果这题用链表或者数组模拟整个过程的话,时间复杂度都将高达O(nk),而n<=10000,k<=100 ...
- Python 解析配置模块之ConfigParser详解-乾颐堂
1.基本的读取配置文件 -read(filename) 直接读取ini文件内容 -sections() 得到所有的section,并以列表的形式返回 -options(section) 得到该sect ...
- 通过input上传图片,判断不同浏览器及图片类型和大小的js代码
1.jsp页面代码 <form id="userPhoto" name="userPhoto" method="post" actio ...
- win7设置开机启动virtualBOX虚拟机
如果常用VirtualBox虚拟机系统的话,设置随开机启动也是很方便的.不需要打开VirtualBox窗口,直接启动VirtualBox虚拟机系统就可以了. 设置开机自启动VirtualBox虚拟机系 ...
- 【转载】Redis的Java客户端Jedis的八种调用方式(事务、管道、分布式…)介绍
转载地址:http://blog.csdn.net/truong/article/details/46711045 关键字:Redis的Java客户端Jedis的八种调用方式(事务.管道.分布式…)介 ...
- Android编程设置LayoutParams
RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams)viewHolder.headerWraper.getL ...
- 编写高质量代码改善C#程序的157个建议——建议112:将现实世界中的对象抽象为类,将可复用对象圈起来就是命名空间
建议112:将现实世界中的对象抽象为类,将可复用对象圈起来就是命名空间 在我们身边的世界中,对象是什么?对象就是事物,俗称“东西”.那么,什么东西算得上是一个对象呢?对象有属性.有行为.以动物为例,比 ...
- SQL语句统计错误率
2018年的第一篇博客就以此作为开端吧 :D 最近在项目中碰到需要统计类似错误率之类的需求,原本这功能是之前做的,但是最近测的时候发现出了点问题,显示的结果不对.这就比较尴尬了... 于是就进行deb ...