之前采用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. VS2017在Release下编译错误C1001

    在使用VS2017编译C程序时,Debug模式下编译链接执行都没有问题,但是一转到Release模式下就出现下列编译链接错误(IDE:VS2017 /VC++/MFC程序,目标平台x86+Win32位 ...

  2. Openssl sess_id命令

    一.简介 sess_id指令是一个调试工具,用来处理SSL_SESSION结构的,可以打印出其中的细节 二.语法 openssl sess_id [-inform PEM|DER] [-outform ...

  3. java判断一个数是否为素数[转]

    http://blog.csdn.net/lwcumt/article/details/8027586 import java.util.Scanner; //质数又称素数,是指在一个大于1的自然数中 ...

  4. 配置GIT DIFF/MERGE TOOL

    关闭prompt backup git config --global difftool.prompt false git config --global mergetool.prompt false ...

  5. AJAX和DHTML

    DHTML: (动态的html)本身不是一门新语言,而是一门新技术,包含以下 html . css . dom . js AJAX  :  也是一门新技术包含    html . css.  dom ...

  6. 福大软工 · BETA 版冲刺前准备(团队) [已完成]

    写在前面 本次作业地址 林燊大哥 过去存在的问题 算法组 没有考虑到数据集不充足的情况.一开始我们将所有数据集按照8:1:1进行分割,分别分配给训练集.开发集和测试集.然鹅后来发现采集到的数据不够充足 ...

  7. 1146 ID Codes

    题目链接: http://poj.org/problem?id=1146 题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 " ...

  8. 基于保守性和规则性的预测方法SIFT和PolyPhen

    有什么特征可以帮助我们来区分导致功能和表型变化的变异和其他变异,然后我们如何综合特征来做出一个预测模型? 表型或功能的改变(phenotypical/functional effect)a,个体表型上 ...

  9. dubbo获取错误ip

    JAVA_OPTIONS="-Ddubbo.protocol.host=192.168.1.111

  10. 如何查找文件中的schema约束

    1.下载一个spring3.2的jar和source 然后打开source的文件(路径:\spring-framework-3.2.5.RELEASE\docs\spring-framework-re ...