从一组图像创建一个电影

时间:2017-09-16 13:43:19

标签: image movie

我有以下代码段:

X=[]
for val in range(64):
   ap_pix=amp_phas[:,val]
   im=plt.imshow(ap_pix.reshape(50,50),cmap=plt.get_cmap('plasma'))
   X.append(im)

amp_phas是一个(2500 x 64)数组,因此循环的每一步都会创建一个存储在数组X中的50 x 50图像。 我在Jupyter笔记本中使用Python 3。

如何从数组X创建电影或幻灯片?

1 个答案:

答案 0 :(得分:0)

我能够使用imageio和mimsave解决这个问题。

这是我的最终代码:

filenames=[]      # array that stores the filename of each image
 for val in range(64):
  ap_pix=amp_phas[:,val]    # array that contains the image data
  im=plt.imshow(ap_pix.reshape(50,50),cmap=plt.get_cmap('plasma'))
  plt.colorbar()
  a='C:/yada/yada/'+ str(val)+'.png'     #filename of each array with the location where it is to be saved
filenames.append(a)    # adding the file name to filenames[] 
plt.savefig(a)      #saving the figure
plt.clf()         #clearing the figure so that the colorbars don't pile up

import imageio
images = []        #array to store the images
for filename in filenames:
  images.append(imageio.imread(filename))  #reading the images into into images[]
imageio.mimsave('C:/yada/yada/movie.gif', images)  #movie making

可以通过以下方式调整gif的帧速率:

  imageio.mimsave('C:/yada/yada/movie.gif', images,duration=0.5)