[英]Python's imageio module doesn't return more than one frame
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: 我有以下关于imageio Python库的代码,它从当前文件夹中加载2个图像,将所有颜色> 200替换为0(使其更暗),然后将结果打印到新的.gif图像:
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. 问题是生成的图像只包含1帧,只有1个图像,而不是我已经在surface1.gif中“合并”的两个图像。 Why is that?
这是为什么?
Using the get_reader
and get_writer
objects you can do it like this: 使用
get_reader
和get_writer
对象可以这样做:
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. 我测试了它并按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.