k-Wave Toolbox Previous   Next

Saving Movie Files Example

Overview

This example demonstrates how to save the simulation animations as a movie. It builds on the Heterogeneous Propagation Medium Example.

 Back to Top

Setting the 'RecordMovie' flag

In the preceding example, the optional inputs 'PlotLayout' and 'PlotPML' were used to change the default behaviour of kspaceFirstOrder2D. Here several other optional inputs are used to save the simulation animation to a movie file. By setting 'RecordMovie' to true, the displayed image frames are saved and exported as a movie with a date and time stamped filename. A user defined filename can also be given by setting the 'MovieName' input to a string. The movie frames are captured using getframe and converted to an avi file using movie2avi. In 2D, the movie frames can alternatively be captured using im2frame by setting the optional input 'MovieType' to 'image' (the default setting is 'frame'). In this case, the size of the movie will depend on the size of the simulation grid. Note, when using getframe (the default setting), if other windows are moved in front of the simulation window, these will also be captured!

% set the input arguments
input_args = {'RecordMovie', true, 'MovieType', 'image', 'MovieName', 'example_movie'};

% run the simulation
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});

 Back to Top

Controlling the movie settings

As the movie frames mimic the frames used for the simulation animation, the properties of the movie can be controlled by changing the animation settings. For example, the image scaling can be set using 'PlotScale', and the number of iterations which must pass before the simulation plot is updated can be controlled via 'PlotFreq'. Note, the default color map used for the animation has zero set to white (see getColorMap), thus using a scaling parameter set to [-a, a] will give the best visual results.

% set the input arguments
input_args = {..., 'PlotScale', [-2, 2], 'PlotFreq', 5, ...};

Optional inputs can also be passed directly to movie2avi via 'MovieArgs'. An example of changing the default frame rate is given below.

% set the input arguments
input_args = {..., 'MovieArgs', {'fps', 30}, ...};

The movies are saved in the same directory as the example m-file.

Note, by default, k-Wave sets 'Compression' to 'Cinepak' for 32-bit Windows, and 'None' for 64-bit Windows and Unix. However, if the compression is set to 'None', the generated video files can become very large. To reduce the size after the movie is created, the open source package Hand Brake can be used to compress and covert the files.

 Back to Top

Changing additional display settings

A wide range of different visualisations can be produced by modifying additional input parameters. For example, a mesh plot can be produced instead of an image plot by setting 'MeshPlot' to true (supported in 2D only), the display mask can be customised or switched off using 'DisplayMask', and the visibility of the PML can be controlled using 'PlotPML'. If no sensor output is required, the sensor input can also be left blank using an empty array.

% set the input arguments
input_args = {..., 'MeshPlot', true, 'DisplayMask', 'off', 'PlotPML', false, ...};

% run the simulation without a sensor input
kspaceFirstOrder2D(kgrid, medium, source, [], input_args{:});

Note, if you see a blank movie when using the option 'MeshPlot' set to true, this can sometimes be solved by running the command opengl('software'). This forces MATLAB to use software OpenGL rendering instead of hardware OpenGL.

 Back to Top


© 2009-2014 Bradley Treeby and Ben Cox.