Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imread() fails on HTTPS, code example from documentation #1030

Closed
MartinMeo opened this issue Aug 13, 2023 · 3 comments
Closed

imread() fails on HTTPS, code example from documentation #1030

MartinMeo opened this issue Aug 13, 2023 · 3 comments

Comments

@MartinMeo
Copy link

Hey folks,

I am brand new with imageio. It looks like np.stack() is throwing
ValueError('all input arrays must have the same shape')
when reading a .gif file via HTTPS from a URL. I tried two different image files with the same result.

The code is directly from documentation examples so why doesn't everyone get this error on day one.
examples reading-from-fancy-sources

I'd appreciate any ideas or insights into the issue.

import imageio.v3 as iio
import io

# from HTTPS
web_image = "https://upload.wikimedia.org/wikipedia/commons/d/d3/Newtons_cradle_animation_book_2.gif"
# web_image = "https://media.giphy.com/media/BPJmthQ3YRwD6QqcVD/giphy.gif"
frames = iio.imread(web_image, index=None)

Traceback (most recent call last):
File "/Users/martinmeo/SW_DEV/PYTHON/2023/IMAGE-IO-LIB/demo.py", line 7, in
frames = iio.imread(web_image, index=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/martinmeo/miniconda3/envs/PATH311/lib/python3.11/site-packages/imageio/v3.py", line 54, in imread
return np.asarray(img_file.read(**call_kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/martinmeo/miniconda3/envs/PATH311/lib/python3.11/site-packages/imageio/plugins/pillow.py", line 234, in read
image = np.stack([im for im in iterator], axis=0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<array_function internals>", line 200, in stack
File "/Users/martinmeo/miniconda3/envs/PATH311/lib/python3.11/site-packages/numpy/core/shape_base.py", line 464, in stack
raise ValueError('all input arrays must have the same shape')
ValueError: all input arrays must have the same shape

HW: MacBook Pro M2
OS: macOS Ventura 13.4.1 (c)
conda 23.3.1
python: 3.11.3
imageio: 2.31.1

@Pandede
Copy link
Contributor

Pandede commented Sep 4, 2023

Try to set mode to RGB or RGBA

frames = iio.imread(web_image, index=None, mode='RGB')

The GIF cannot be read properly as the first frame has a different dimension to the others, therefore numpy unable to stack the frames with different shape:

from collections import Counter

from PIL import Image, ImageSequence

web_image = "Newtons_cradle_animation_book_2.gif"
gif_image = Image.open(web_image)

mode_counter = Counter(
    frame.mode
    for frame in ImageSequence.Iterator(gif_image)
)
print(mode_counter)  # Counter({'RGBA': 35, 'P': 1})

@Pandede
Copy link
Contributor

Pandede commented Sep 4, 2023

This bug is also mentioned in PR of Pillow: python-pillow/Pillow#6150

@FirefoxMetzger
Copy link
Contributor

Fixed by #1036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants