gpt4 book ai didi

python - 通过 skimage.io.imread 读取的图像形状可疑

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:02 25 4
gpt4 key购买 nike

我正在尝试使用 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,有人可以解释一下我使用这个包的方式有什么问题吗?或者这真的是一个错误吗?

单击测试图像的链接

编辑1

测试图片在上传时有改动,未改动的版本为here .我也开了an issue在 skimage github repo 上,结果是测试图像是双帧图像,但第二帧是空的。你可以考虑这张图片“损坏”的图像。

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

最佳答案

您可以通过强制 skimage.io.imread() 使用 ma​​tplotlib 来解决这个问题:

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)

看看this thread了解有关此问题的更多信息。

关于python - 通过 skimage.io.imread 读取的图像形状可疑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41196754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com