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)
    196                 fio = io.BytesIO(pixel_data)
--> 197                 decompressed_image = Image.open(fio)
    198             except IOError as e:

c:\python35\lib\site-packages\PIL\Image.py in open(fp, mode)
   2571     raise IOError("cannot identify image file %r"
-> 2572                   % (filename if filename else fp))
   2573 

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-55-c00f3f09682d> in <module>()
----> 1 file.pixel_array

c:\python35\lib\site-packages\pydicom\dataset.py in pixel_array(self)
    899             The Pixel Data (7FE0,0010) as a NumPy ndarray.
    900         """
--> 901         self.convert_pixel_data()
    902         return self._pixel_array
    903 

c:\python35\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self)
    845         )
    846 
--> 847         raise last_exception
    848 
    849     def decompress(self):

c:\python35\lib\site-packages\pydicom\dataset.py in convert_pixel_data(self)
    813             try:
    814                 # Use the handler to get a 1D numpy array of the pixel data
--> 815                 arr = handler.get_pixeldata(self)
    816                 self._pixel_array = reshape_pixel_array(self, arr)
    817 

c:\python35\lib\site-packages\pydicom\pixel_data_handlers\pillow_handler.py in get_pixeldata(dicom_dataset)
    197                 decompressed_image = Image.open(fio)
    198             except IOError as e:
--> 199                 raise NotImplementedError(e.strerror)
    200             UncompressedPixelData.extend(decompressed_image.tobytes())
    201     except Exception:

NotImplementedError: None

看到一篇博客https://blog.csdn.net/inter_peng/article/details/74370306与我的问题类似,都出在dicom文件格式上面,这种压缩格式用pydicom读取不出来,采用SimpleITK可以解决

file = sitk.ReadImage(filepath)
data = sitk.GetArrayFromImage(file)

 

转载于:https://www.cnblogs.com/wzyuan/p/10489499.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值