I want to be able to transform numpy arrays into images. First, I have learned how to transform a 3D (hight x width x color
) array into an image. After some research it looks to me that PIL (or Pillow) is the most natural way to do it. This is how I do it at the moment (and it works fine):
from PIL import Image
import numpy as np
if __name__ == '__main__':
h = 4
w = 8
arr = np.zeros((h,w,3), dtype=np.uint8)
arr[0, 0, :] = [255,255,0]
arr[3, 7, :] = [0,255,0]
img = Image.fromarray(arr, 'RGB')
img.save('viz.png')
As a next step, I want to be able to take a list of 3D array (or a 4D array, where time is the additional dimension) and generate the corresponding animation. So, far I did not find how to do it.
It looks like Pillow is able to read gif-animation. Using ImageSequence we can access its frames. However, I cannot find out how one can put a sequence of images into animation.
I saw some solutions that use ìmages2gif
but I would like to stay withing a single library.
ADDED
The answers here do not answer my question. They use gifmaker
library that I cannot even install by pip.