通过skimage.io.imread读取的图像具有可疑形状

jdh*_*hao 3 python scikit-image

我正在尝试使用skimage.io.imread读取RGB图像。但是看完图像后,发现图像形状有误,print(img.shape)说明图像形状是(2,)。显示问题的完整代码是:

from skimage import io
img = io.imread(path/to/the/image)
print(img.shape)
Run Code Online (Sandbox Code Playgroud)

我还尝试使用opencv的python包读取图像,返回的形状正确(height * width * 3)。

使用的skimage版本是0.12.3,有人可以解释我使用该软件包的方式有什么问题吗,或者这真的是一个错误吗?

点击以下链接 测试图像

编辑1

上载测试图像后,它会更改,未更改的版本在这里。我还在skimage github存储库上打开了一个问题,事实证明测试图像是两帧图像,但是第二帧是空的。您可以将此图像视为“损坏的”图像。

为了阅读正确的图像,您可以使用此解决方法img = io.imread(/path/to/the/image, img_num=0)

Ton*_*has 7

您可以通过强制skimage.io.imread()使用matplotlib来解决此问题:

In [131]: from skimage import io

In [132]: img = io.imread('156.jpg', plugin='matplotlib')

In [133]: img.shape
Out[133]: (978L, 2000L, 3L)
Run Code Online (Sandbox Code Playgroud)

您的图像可能是多对象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)
Run Code Online (Sandbox Code Playgroud)

看一下该线程,以了解有关此问题的更多信息。