之前采用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文件报错的更多相关文章

  1. python3 读取dbf文件报错 UnicodeDecodeError: 'gbk' codec can't decode

    在读取dbf文件时由于编码问题报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 49: incomplete ...

  2. 解决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 ...

  3. 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 ...

  4. 【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 ...

  5. 读取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- ...

  6. python读取xml文件报错ValueError: multi-byte encodings are not supported

    1.在使用python对xml文件进行读取时,提示ValueError: multi-byte encodings are not supported 很多贴子上说把xml的编码格式改为,就可以正常执 ...

  7. .net 读取Excel文件报错

    错误内容 Microsoft Office Excel 不能访问文件“D:\WWWRoot\Website\Test\Excels\Test1.xls”. 可能的原因有: 1 文件名称或路径不存在. ...

  8. [解决问题] pandas读取csv文件报错OSError解决方案

    python用padans.csv_read函数出现OSError: Initializing from file failed 问题:文件路径中存在中文 解决办法:修改文件路径名为全英文包括文件名

  9. 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 ...

随机推荐

  1. C程序之包含头文件

    在C程序中包含文件有以下两种方法: 方法一:#include<XXX.h> 这里的XXX一般是改动较小的标准库,用符号"<"和">"将要 ...

  2. Openssl base64命令

    一.简介 对文件件进行base64的编码与解码 二.语法 openssl base64 [-in filename] [-out filename] 三.实例 1.二进制文件与base64编码互转 o ...

  3. Python爬虫实战三之实现山东大学无线网络掉线自动重连

    综述 最近山大软件园校区QLSC_STU无线网掉线掉的厉害,连上之后平均十分钟左右掉线一次,很是让人心烦,还能不能愉快地上自习了?能忍吗?反正我是不能忍了,嗯,自己动手,丰衣足食!写个程序解决掉它! ...

  4. js改变触发

    onchange="doEmpty($(this))"

  5. 导入excel精华版

    //须引入 NPOI, NPOI.OOXML, NPOI.Openxml4Net, NPOI.OpenxmlFormats等程序集 自己去下载吧 NPOI组件很好用不可能下不到自己去吧,通常去百度网盘 ...

  6. hdu 1686 KMP算法

    题意: 求子串w在T中出现的次数. kmp算法详解:http://www.cnblogs.com/XDJjy/p/3871045.html #include <iostream> #inc ...

  7. python基础借鉴

    这是一个链接 这个是egon的链接 吴沛其的博客

  8. python nose的html报告优化

    用的是nose的nose-html-reporting (0.2.3)插件生成报告.用了bootstrap前端框架,加入了开始时间和计算持续时间,及其本地化. 优化后的显示效果: 代码地址

  9. java程序员修炼之前笔记(前半部分)

    第一部分 用java7做开发 第一章 初始java7 java7中的新特性 switch支持String 支持100_000_000数值表示法 新的异常处理 | 连接多个异常 final Except ...

  10. Reporting Service服务SharePoint集成模式安装配置(8、配置用于SharePoint 2010的Reporting service模式)

    从SQL Server 2012 起, SQL Server Reporting Service可以完全集成进SharePoint的场,直接作为SharePoint 的组件部分来运行,没有独立的Win ...