Skip to content Skip to sidebar Skip to footer

Image Read Through Skimage.io.imread Have Suspicious Shape

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,

Solution 1:

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)

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 at0x111DBCF8>, dtype=object)

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

Solution 2:

Check the type of image being uploaded by you.

If you upload a color image you will get the size of the image along with the number of channels (1920, 2560, 3).

As long as the uploaded image is a color image you will receive 3.

Or else if the image is a gray-scale or binary you will get the size of the image (1920, 2560)

Post a Comment for "Image Read Through Skimage.io.imread Have Suspicious Shape"