通过 skimage.io.imread 读取的图像形状可疑 [英] image read through skimage.io.imread have suspicious shape

查看:73
本文介绍了通过 skimage.io.imread 读取的图像形状可疑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to read an RGB image using the skimage.io.imread. But after reading the image, I found that the image shape is wrong, print(img.shape) shows that the image shape is (2,). The complete code to show the problem is:

from skimage import io
img = io.imread(path/to/the/image)
print(img.shape)

我也试过用opencv的python包读取图片,返回的形状是正确的(高*宽*3).

I also tried to read the image using opencv's python package, the returned shape is correct (height*width*3).

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

The skimage version used is 0.12.3, can someone explain is there anything wrong with my way using the package or is this really a bug?

点击测试图片

测试图片上传时有改动,未改动的版本在这里.我还在 skimage github repo 上打开了一个问题,它原来测试图像是一个双帧图像,但第二帧是空的.你可以考虑这张图损坏"的图像.

The test image is altered when it is uploaded, the unaltered version is here. I have also opened an issue on the skimage github repo, and it turns out that the test image is a two-frame image, but the second frame is empty. You can consider this image a "corrupted" image.

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

In order to read the right image, you can use this workaround, img = io.imread(/path/to/the/image, img_num=0).

推荐答案

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

You can fix this issue by enforcing skimage.io.imread() to use 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)

您的图片很可能是多对象 JPG.如果您尝试使用 PIL(这是默认插件)读取它,您会得到一个由两个对象组成的 NumPy 数组.第一个对象是图像本身,第二个对象可能是缩略图,但 PIL 无法正确处理它:

Your image is likely to be a multi object JPG. If you try to read it using PIL (which is the default plugin) you get a NumPy array which consists of two objects. The first object is the image itself and the second one might be a thumbnail, but PIL does not handle it properly:

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)

查看此主题以了解更多信息问题.

Take a look at this thread to find out more on this problem.

这篇关于通过 skimage.io.imread 读取的图像形状可疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆