【问题标题】:Create a movie from an array of images从一组图像创建电影
【发布时间】:2017-09-24 22:12:42
【问题描述】:

我有以下代码sn-p:

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) 数组,因此循环的每一步都会创建一个 50 x 50 的图像,并存储到数组 X 中。 我在 Jupyter 笔记本中使用 Python 3。

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

【问题讨论】:

  • 请在您的问题中添加更多详细信息。您使用哪种编程语言?您需要的确切输出是什么?创建电影并不能清楚地描述您想要的输出。

标签: image movie


【解决方案1】:

我能够使用 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)

【讨论】:

    猜你喜欢
    • 2012-02-10
    • 1970-01-01
    • 2016-11-22
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 2012-10-06
    相关资源
    最近更新 更多