使用 R 中的一系列情节创建电影

发布于 2024-08-02 10:32:08 字数 1436 浏览 7 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

蔚蓝源自深海 2024-08-09 10:32:08

这是我使用 R 帮助找到的一种方法:

创建单独的图像帧:

jpeg("/tmp/foo%02d.jpg")
for (i in 1:5) {
  my.plot(i)
}
dev.off()

要制作电影,首先安装 ImageMagick
然后调用以下函数(它调用“convert”,我想是 ImageMagick 的一部分):

make.mov <- function(){
     unlink("plot.mpg")
     system("convert -delay 0.5 plot*.jpg plot.mpg")
}

或者尝试使用 ffmpeg 函数,如本 文章(我发现这给出了更清晰的结果):
ffmpeg -r 25 -qscale 2 -i tmp/foo%02d.jpg output.mp4

可能需要一些修补,但是一旦安装了所有东西,这看起来就很简单了。

当然,无论您在哪里看到“jpg”或“jpeg”,都可以替换为 GIF 或 PNG 以满足您的喜好。

Here is one method I found using R help:

To create the individual image frames:

jpeg("/tmp/foo%02d.jpg")
for (i in 1:5) {
  my.plot(i)
}
dev.off()

To make the movie, first install ImageMagick.
Then call the following function (which calls "convert", part of ImageMagick I suppose):

make.mov <- function(){
     unlink("plot.mpg")
     system("convert -delay 0.5 plot*.jpg plot.mpg")
}

Or try using the ffmpeg function as described in this article (I've found this gives cleaner results):
ffmpeg -r 25 -qscale 2 -i tmp/foo%02d.jpg output.mp4

May require a bit of tinkering, but this seemed pretty simple once everything was installed.

Of course, anywhere you see "jpg" or "jpeg", you can substitute GIF or PNG to suit your fancy.

能否归途做我良人 2024-08-09 10:32:08

查看由 动画 包href="https://yihui.org/animation/" rel="nofollow noreferrer">谢益辉 或 EBImage 生物导体包 (?animate)。

Take a look at either the animation package created by Yihui Xie or the EBImage bioconductor package (?animate).

谢绝鈎搭 2024-08-09 10:32:08

我认为您也可以使用 caTools 库中的 write.gif 函数来完成此操作。您必须首先将图形转换为多帧图像。我不知道该怎么做。有人吗?布勒?

动画 GIF 的经典示例是这段代码,它不是我编写的,但我在 博客中编写了 前段时间:

library(fields) # for tim.colors
library(caTools) # for write.gif
m = 400 # grid size
C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C = matrix(C,m,m)

Z = 0
X = array(0, c(m,m,20))
for (k in 1:20) {
Z = Z^2+C
X[,,k] = exp(-abs(Z))
}

image(X[,,k], col=tim.colors(256)) # show final image in R
write.gif(X, 'Mandelbrot.gif', col=tim.colors(256), delay=100)

代码归 Jarek Tuszynski 博士所有。

I think you can do this also with the write.gif function in the caTools library. You'd have to get your graph into a multi-frame image first. I'm not sure how to do that. Anyone? Bueller?

The classic example of an animated GIF is this code which I didn't write but I did blog about some time ago:

library(fields) # for tim.colors
library(caTools) # for write.gif
m = 400 # grid size
C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C = matrix(C,m,m)

Z = 0
X = array(0, c(m,m,20))
for (k in 1:20) {
Z = Z^2+C
X[,,k] = exp(-abs(Z))
}

image(X[,,k], col=tim.colors(256)) # show final image in R
write.gif(X, 'Mandelbrot.gif', col=tim.colors(256), delay=100)

Code credit goes to Jarek Tuszynski, PhD.

揽清风入怀 2024-08-09 10:32:08

如果您将 R 脚本包装在更大的 Perl/Python/等中。脚本,您可以使用您最喜欢的命令行图像拼接工具将图形拼接在一起。

要使用包装器脚本运行 R 脚本,请使用 R CMD BATCH 方法。

If you wrap your R script within a larger Perl/Python/etc. script, you can stitch graphs together with your favorite command-line image stitching tool.

To run your R script with a wrapper script, use the R CMD BATCH method.

故笙诉离歌 2024-08-09 10:32:08

我不确定这在 R 中是否可行。我曾经做过一个项目,将 R 中的数据点导出到 MySQL 数据库,然后 Flex/Flash 应用程序拾取这些数据点并提供动画可视化。

I'm not sure it is possible in R. I did a project once when data points from R were exported to a MySQL database and a Flex/Flash application picked up those data points and gave animated visualizations..

攀登最高峰 2024-08-09 10:32:08

我使用 XNview(免费软件图形查看器)的创建幻灯片功能制作了一些电影。我想用空间数据显示随时间变化的趋势,所以我只是创建了一系列图,按顺序命名[paste() 是你各种命名 Calistethics 的朋友],然后将它们加载到 XNviews 幻灯片对话框中并设置一些计时器变量,瞧。花了大约 5 分钟来学习如何操作并生成一些可执行图形。

I've done some movies using XNview's (freeware graphics viewer) Create Slideshow function. I wanted to show trends through time with spatial data, so I just created a series of plots, named sequentially [paste() is your friend for all sorts of naming calistethics] then loaded them into XNviews slideshow dialogue and set a few timer variables, voila. Took like 5 minutes to learn how to do it and produce some executable graphics.

栖竹 2024-08-09 10:32:08

以下是从 HDF5 文件制作动画 GIF“电影”的完整示例。数据应该是 3 维数组 [Nframes][Nrows][Ncolumns] 的 HDF 数据集。

#
# be sure to be run as Administrator to install new packages
#
source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")
install.packages('caTools')
install.packages('fields')

library(caTools)
library(fields)
library(rhdf5)

x = h5read(file="mydata.h5",name="/Images")
write.gif(x,"movie1.gif",col=rainbow,delay=10,flip=TRUE)

Here's a full example on making an animated GIF "movie" from an HDF5 file. The data should be an HDF Dataset of a 3 dimensional array [Nframes][Nrows][Ncolumns].

#
# be sure to be run as Administrator to install new packages
#
source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")
install.packages('caTools')
install.packages('fields')

library(caTools)
library(fields)
library(rhdf5)

x = h5read(file="mydata.h5",name="/Images")
write.gif(x,"movie1.gif",col=rainbow,delay=10,flip=TRUE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文