0

When saving an animated GIF from a Numpy array of shape (20, 64, 64, 3) and loading it again, the shape is suddenly (20, 64, 64). I think the array may contain indices into a color palette but I'm not sure how to access that. How can I restore the original data from the saved GIF?

import imageio
import numpy as np

imageio.mimsave('animation.gif', np.zeros((20, 64, 64, 3)))
np.array(imageio.mimread('animation.gif')).shape  # (20, 64, 64)
danijar
  • 32,406
  • 45
  • 166
  • 297
  • I think the image is compressed. Maybe try `np.random.randint(0, 256, (20, 64, 64, 3), dtype=np.uint8)` instead of all zeros? – Sraw Aug 01 '19 at 02:40
  • Thanks. Yes, loading that gives an array with 4 channels (RGBA). However, I don't know what my user will put into the image. Is there a way to automatically convert the compressed image back into four channels? – danijar Aug 01 '19 at 13:35

0 Answers0