python - scikit-image 无法导入图像
问题描述
环境:
- Python 3.7.0
- 创建 virtualenv 后,scikit-image 是通过 pip 安装的。
scikit-image==0.16.2
,Pillow==7.1.1
- Linux 上的 Anaconda
源代码:
from skimage.io import imread
file_path = "image_you_like.png"
img = imread(file_path, plugin="pil", as_gray=False)
预期结果:
img
是图像的 numpy 数组。
实际结果:
不要相信行号,因为我插入了几个打印函数。
~/Python/experiment/venv/lib/python3.7/site-packages/PIL/PngImagePlugin.py in _seek(self, frame, rewind)
789
790 try:
--> 791 cid, pos, length = self.png.read()
792 except (struct.error, SyntaxError):
793 break
AttributeError: 'NoneType' object has no attribute 'read'
问题
如何防止此错误并读取图像?
经过一些分析,我发现imread
如果plugin="matplotlib"
或plugin="imageio"
. 问题是某些功能,例如skimage.data.camera
调用imread
,plugin="pil"
因此我无法尝试任何示例图像scikit-image
。
[编辑]
from skimage.io.manage_plugins import plugin_store
print(plugin_store["imread"])
打印以下内容
[('imageio', <function imread at 0x7efe39112c20>), ('matplotlib', <function imread at 0x7efe37f51290>)]
所以在列表中找不到“pil”。
解决方案
此问题已在 github 上报告。
作为用户,最简单的解决方案是将版本降级到 6.2.2。
推荐阅读
- javascript - 如何根据laravel中的选定下拉菜单重定向到另一个页面
- node.js - Mongodb返回错误:“data”参数必须是字符串类型或Buffer、TypedArray或DataView的实例。收到 MongoError 的实例
- swiftui - 不在小部件中时如何设置 .widgetFamily @Environment 变量?
- html - 内联 flex 添加空格
- firebase - 错误:错误状态:DocumentSnapshotPlatform 中不存在字段
- android - 评估项目 ':app' 时出现问题。Flutter 构建 Appbundle 错误
- python - 使用 Python 编辑 CSV 文件
- svg - html2canvas 不渲染 svg(图表行)
- node.js - nodejs api post方法不起作用,无法/post错误
- mongodb - 在 3.6 之前的 mongo 版本中,$expr 的替代品是什么?