The animate package in R has a function saveVideo that saves images as a video format.
From the documentation:
saveVideo(expr, video.name = "animation.mp4", img.name = "Rplot",
ffmpeg = ani.options("ffmpeg"), other.opts = if (grepl("[.]mp4$",
video.name)) "-pix_fmt yuv420p", ...)
and it seems the 'bit-rate' needs to be specified under other-opts.
I don't fully understand what bit-rate means here, and how it is supposed to be specified other than just trial and error, and how it relates to the resolution of the output.
In R, we also have the function png() which saves images, where one can specify width, height, and res. I'd like to do something similar here. Is there a guideline for how to choose bit-rate so that I get the desired size and quality for the video?
Have you taken a look at the documentation page for ani.options?
Among those that seem to answer your are ani.width, ani.height
, and ani.resto manually adjust the width, height, and resolution of your animation.
Related
I am working on a simple script to get mean value from a ImageCollection(). To do this I am using ImageCollection.reduce(ee.Reducer.mean()).
My problem is that the Image returned is coming with a different nominalScale().
I already looked at the documentation but couldn't figure out why this results. As you can see on ee.ImageCollection.reducer() there is no parameter specifying the scale; nor on ee.Reducer.mean().
What am I doing wrong?
Again, I am basically trying to do do something like this. Actually this tutorial shows an image which made me believe I wouldn't have changes on pixel resolution...
My code:
var WorldClim = ee.ImageCollection("WORLDCLIM/V1/MONTHLY");
print("WorldClim original", WorldClim.first().projection().nominalScale());
var WorldClim = WorldClim.select("prec");
print("Apenas prec:", WorldClim.first().projection().nominalScale());
var MeanPrec = WorldClim.reduce(ee.Reducer.mean());
print("Após reduce(ee.Reducer.mean())", MeanPrec.projection().nominalScale());
https://code.earthengine.google.com/3e3bff9030fd9ff70b052b2beb4daced
That is most likely due to the image pyramiding of image. Since the mean image is a temporary object only in memory buffer, it should not have a base nominal scale and since the tiles are computed based on whatever zoom level your map is currently at.
However, there is a way you can fix this if you specifically want to work with the resolution of the source image. You basically have to reproject the image to the same one the original has. One way to do this would be to change the line where you compute mean to
var MeanPrec = WorldClim.reduce(ee.Reducer.mean()).reproject({
crs:WorldClim.first().projection(),
scale:WorldClim.first().projection().nominalScale()
});
This may sound weird, or impossible but I can say the scale of the output plot when you compile inside R and view it without zooming or exporting works great for me. However, when I export to pdf, the plot becomes outrageously large and I never manage to scale it to what I see inside R. Am I being silly, or there is actually a difference and there is a way to get what I see inside that bottom-left-corner box of the R.
use ggsaves width and length arguments to get the desired size.
ggsave('name.pdf', width =14, height = 8)
I am in need of a way to increase the resolution of the png files created by saveHTML().
Here is a dummy script of what I am trying to do where in reality plot() is a number of nested loops:
x<-y<-rep(1,10)
saveHTML( for (i in 1:10){
plot.new()
plot.window(xlim=c(0,10),ylim=c(0,10))
plot(x[i],y[i])
}
,ani.dev="png",img.name="test",htmlfile="test")
A few things I have tried:
1) increase the animation size using ani.options(ani.height,ani.width) but I only get a larger grainy image.
2) call png() device inside the saveHTML expression and set the resolution there, but ultimately I dont get any figures.
3) call a new windows() device for plotting and setting the window size, but again this does not increase the resolution.
The most straight forward work-around that I came across is to create hi-res pngs and animate using ffmpeg. But I am not ready to re-work my script just yet.
Has anyone found a way to increase png resolution inside the saveHTML() function?
Instead of passing ani.dev="png", you can pass ani.dev = function(...){png(res=75*grain,...)}, where grain is some number > 1. If you specify the options ani.height and/or ani.width and multiply these values by the same factor grain, then you effectively increase the pixel resolution of the output by this factor.
N.B.: the default resolution 75 above might be machine dependent, I did not see it documented.
I am saving several plots, made with rgl's functions plot3d and snapshot3d. I need to save some at very high resolution, higher my screen.
When I use
par3d("windowRect" = c(x,y,w,h))
to set the window dimension just before calling snapshot3d it works but the resolution is limited to my monitor's width or height.
Is there a way to break this limit?
Thank you all for your time.
The solution I found to save in high resolution is to move away from the snapshot3d function and use rgl.postscript to save to a vector format like svg. This allows me to rasterize later with the resolution I want.
Example:
rgl.postscript("graph.svg", fmt="svg")
The function rgl.snapshot really grabs a snapshot from the device and I think there's no way to break screen's boundaries using this function unless, as Ben Bolker points out in the comments (thanks), a virtual frame buffer is used.
How do I export a re-sized version of the output I get from a call to GraphPlot
(or TreePlot if they produce different output) to a jpg file?
Currently, I'm simply calling Export[file_name, G]
where G is the result from a call to something like GraphPlot.
I'm using Microsoft office picture manager to view the jpgs,
but re-scaling them there yields unsatisfactory results due to poor resolution
(the graph I'm trying to plot has strings as labels which can't be made out after rescaling this way). I would like to be able to choose the size/resolution of the rendered jpg.
As Simon already pointed out, don't use a raster-format for a vector-graphics. Instead, export you plot to e.g. a scalable vector graphics:
graph = GraphPlot[ExampleData[{"Matrix", "HB/can_292"}, "Matrix"]];
Export["graph.svg", graph]
The advantage is, that in such an image, you can still adjust and change lines, polygons and colors. And finally, you can export it to an image of arbitrary quality easily.
And remember, for Plots which contain lines, polygons, ... everything with sharp edges you should never use jpg. General speaking, this is a format for photographs only since its compression is made for reducing filesize in natural images. In those images you don't recognize the compression, in images with text, lines and polygons you certainly will notice the artefacts. Use png if possible. Take your browser and zoom into the above image.
You can set both image size and compression level of the exported file by doing something like
Export[file_name, G, ImageSize -> 1200, "CompressionLevel" -> 0]
The best way I find is to use ImageResolution property. It Increases the resolution of exported image but does not change the scale. Use it like this:
Export[ "image-file-name.png", image, ImageResolution -> 500 ]
Set the size of your graph before exporting it:
Graph[theGraph, ImageSize->2000]