1

I've the following code about the imageio Python library, which loads 2 images I have from the current folder, replaces all the colors > 200 with 0 (making it darker), and then printing the result to a new .gif image:

import imageio
import numpy as np

im = 'image1.png'
im2 = 'image2.png'
images = []
images.append(imageio.imread(im))
images.append(imageio.imread(im2))
imageio.mimsave('surface1.gif', images, duration = 0.5)

im4 = imageio.imread('surface1.gif')
im4[im4 > 200] = 0
imageio.imwrite('movie.gif', im4, format='gif')

The problem is that the generated image contains only 1 frame, only 1 image, not both of the images which I already "merged" in a surface1.gif. Why is that?

Madno
  • 910
  • 2
  • 12
  • 27

1 Answers1

0

Using the get_reader and get_writer objects you can do it like this:

import imageio
import numpy as np

im = 'image1.png'
im2 = 'image2.png'
images = []
images.append(imageio.imread(im))
images.append(imageio.imread(im2))
imageio.mimsave('surface1.gif', images, duration = 0.5)

im4 = imageio.get_reader('surface1.gif')
writer = imageio.get_writer('movie.gif', duration = 0.5)
for im in im4:
    im[im > 200] = 0
    writer.append_data(im[:, :, :])
writer.close()  

I tested it and works as expected.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Mr K.
  • 1,064
  • 3
  • 19
  • 22