我正在尝试使用 skimage.io.imread 读取 RGB 图像。但看完图片后发现图片形状不对,print(img.shape)
表明
图像形状是(2,)
。显示问题的完整代码是:
from skimage import io
img = io.imread(path/to/the/image)
print(img.shape)
我还尝试使用opencv的python包读取图像,返回的形状是正确的(高度*宽度*3)。
使用的skimage版本是0.12.3,有人可以解释一下我使用该包的方式有什么问题吗?或者这真的是一个错误吗?
Click the link for the test image
Edit1
测试图片上传时有改动,未改动的版本为here https://github.com/csucat/markdown_photos/blob/master/156.jpg。我也开了an issue https://github.com/scikit-image/scikit-image/issues/2406在 skimage github repo 上,结果发现测试图像是
双帧图像,但第二帧是空的。你可以考虑这张图
“损坏”的图像。
为了读取正确的图像,您可以使用此解决方法,img = io.imread(/path/to/the/image, img_num=0)
.
您可以通过强制执行来解决此问题skimage.io.imread()
to use 绘图库:
In [131]: from skimage import io
In [132]: img = io.imread('156.jpg', plugin='matplotlib')
In [133]: img.shape
Out[133]: (978L, 2000L, 3L)
您的图像可能是多对象 JPG。如果您尝试使用以下方式阅读它PIL(这是默认插件)你会得到一个由两个对象组成的 NumPy 数组。第一个对象是图像本身,第二个对象可能是缩略图,但 PIL 无法正确处理它:
In [157]: img = io.imread('156.jpg', plugin='pil')
In [158]: img.dtype
Out[158]: dtype('O')
In [159]: img.shape
Out[159]: (2L,)
In [160]: img[0].shape
Out[160]: (978L, 2000L, 3L)
In [161]: img[1]
Out[161]: array(<PIL.MpoImagePlugin.MpoImageFile image mode=RGB size=2000x978 at 0x111DBCF8>, dtype=object)
看一眼这个线程 https://github.com/scikit-image/scikit-image/issues/2154了解有关此问题的更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)