k-Wave Toolbox |

## Saving Movie Files Example

On this page…
Overview Setting the 'RecordMovie' flag Controlling the movie settings Changing additional display settings

### Overview

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

- open the file in the MATLAB Editor
- run the file in MATLAB

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 an arbitrary 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 those used for the simulation animation, the output can be controlled by changing the animation settings. 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}, ...};

Note, by default k-Wave sets `'Compression'` to `'Cinepak'` for 32-bit Windows, and `'None'` for 64-bit Windows and Unix. The movies are saved in the same directory as the example m-file.

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{:});

The open source package Hand Brake can be used for converting and compressing the movies created using MATLAB.

Back to Top

© 2009, 2010, 2011 Bradley Treeby and Ben Cox.