| Image Processing Toolbox™ | ![]() |
| On this page… |
|---|
Viewing Image Sequences in the Movie Player |
Some applications create collections of images related by time, such as frames in a movie, or by (spatial location, such as magnetic resonance imaging (MRI) slices. These collections of images are referred to by a variety of names, such as image sequences, image stacks, or videos.
The toolbox represents image sequences as four-dimensional arrays, where each separate image is called a frame, all frames are the same size, and the frames are concatenated along the fourth dimension. imtool and imshow can display one frame at a time, using standard MATLAB array indexing syntax, but cannot animate the sequence or provide any navigation within the sequence. A better choice to view image sequences is the Movie Player (implay). The Movie Player can animate the display of frames in an image sequence and provides playback controls that you can use to navigate among the frames in the sequence. To get a static view of all the frames in an image sequence at one time, use the montage function. For more information, see these additional topics.
This section describes how to use the Movie Player to view image sequences and provides information about configuring the Movie Player.
Load the image sequence into the MATLAB workspace. For this example, load the MRI data from the file mristack.mat, which is included in the imdemos directory.
load mristack
This places a variable named mristack in your workspace. The variable is an array of 21 grayscale frames containing MRI images of the brain. Each frame is a 256-by-256 array of uint8 data.
mristack 256x256x21 1276256 uint8
View the image sequence in the Movie Player. Call implay, specifying the name of the image sequence variable as an argument. You can also specify the name of a file that contains an image sequence, such as an Audio Video Interleaved (AVI) file.
implay(mristack)
You can also import an image sequence from the workspace into the Movie Player using the Import from workspace option on the File menu.
The Movie Player opens, displaying the first frame of the image sequence. Note how the Movie Player displays information about the image sequence, such as the size of each frame and the total number of frames, at the bottom of the window.

Explore the image sequence using Movie Player Playback controls.
To view the image sequence or video as an animation, click the
Play button
in the Playback toolbar, select Play from
the Playback menu, or press P or the Space bar. By
default, the Movie Player plays the image sequence forward, once in
its entirety, but you can view the frames in the image sequence in
many ways, described in this table. As you view an image sequence,
note how the Movie Player updates the Status Bar at the bottom of
the window.
| Viewing Option | Playback Control | Keyboard Shortcut |
|---|---|---|
| Specify the direction in which to play the image sequence. | Click the Playback mode button
| A |
| View the sequence repeatedly. | Click the Repeat button
| R |
| Jump to a specific frame in the sequence. | Click the Jump to button
| J |
| Stop the sequence. | Click the Stop button
| S |
| Step through the sequence, one frame at a time, or jump to the beginning or end of the sequence (rewind). | Click one of the navigation buttons
| Arrow keysPage Up/Page Down L (last frame) F (first frame) |
Change the view of the image sequence or examine a frame more closely.
The Movie Player supports several tools listed in the Tools menu and on the Toolbar that you can use to examine the frames in the image sequence more closely.
| Viewing Option | Playback Control |
|---|---|
| Zoom in or out on the image, and pan to change the view. | Click one of the zoom buttons
|
| Examine an area of the current frame in detail. | Click the Pixel region button
|
| Export frame to Image Tool | Click the Export to Image tool button
|
The Movie Player Configuration dialog box enables you to change the appearance and behavior of the player. To open the Configuration dialog box, select File > Configuration Set > Edit. (To load a preexisting configuration set, select File > Configuration Set > Load.)
The Movie Player displays the Configuration dialog box. This dialog box contains three panes, Core, Sources, and Tools, which each offer various options. On each pane, you can select a category and then click Options to view configuration settings.

The following table lists the options that are available for each category on every pane.
| Pane | Option Category | Option Descriptions |
|---|---|---|
| Core | General UI | Display the full source path in the title bar check box — Select to display the full path to the video data source in the title bar. By default, Movie Player displays a shortened name in the title bar. Message log opens when menu — Specify when the Message log window opens. You can use the Message log window to debug issues with video playback. By default, the window only opens for failure messages. |
| Core | Source UI | Keyboard commands respect playback mode check box — Select to make keyboard shortcut keys aware of your playback mode selection. If you clear this check box, the keyboard shortcut keys behave as if the playback mode is set to Forward play and Repeat is set to off. Recently used sources list parameter — Specifies the number of sources listed in the File menu. |
| Source | File | Select the Enabled check box next to enable connections to files (the default). Recently opened file path parameter — Specify the directory that is displayed in the Connect to File dialog box when you click File > Open. |
| Source | Workspace | Select the Enabled check box next to enable connections to variables in the workspace (the default). There are no options associated with this selection. |
| Source | Simulink | Select the Enabled check box next to enable connections to Simulink models. You must have Simulink installed. |
| Tools | Image Tool | Select the Enabled check box to include
the Image Tool. Open new Image Tool window for export check box — Opens a new Image Tool for each exported frame. |
| Tools | Pixel Region | Select the Enabled check box to include the Pixel Region tool in the Movie Player (the default). |
| Tools | Image Navigation Tools | Select the Enabled check box to include the zoom and pan tools in the Movie Player (the default). |
| Tools | Instrumentation Sets | Select the Enabled check box to include instrumentation sets in the Movie Player. Provides a way to save your current configuration. |
Saving Your Configuration Settings. To save your configuration settings for future use, select File > Configuration Set > Save as.
Note By default, the Movie Player uses the configuration settings from the file implay.cfg. If you want to store your configuration settings in this file, you should first create a backup copy of the file. |
To decrease or increase the playback rate, select Frame Rate from the Playback menu, or use the keyboard shortcut T. The Frame Rate dialog box displays the frame rate of the source, lets you change the rate at which the Movie Player plays the image sequence or video, and displays the actual playback rate. The playback rate is the number of frames the Movie Player processes per second.

If you want to increase the actual playback rate, but your system's hardware cannot keep up with the desired rate, select the Allow frame drop to achieve desired playback rate check box. This parameter enables the Movie Player to achieve the playback rate by dropping frames. As a result, the playback might appear choppy. When you select this option, the Frame Rate dialog box displays several additional options that you can use to specify the minimum and maximum refresh rates. To achieve a smoother playback, increase the refresh rate.
To specify the colormap to apply to the intensity values, select Colormap from the Tools menu, or use the keyboard shortcut C. The Movie Player displays a dialog box that enables you to change the colormap.

Use the Colormap parameter to specify a particular colormap.
If you know that the pixel values do not use the entire data type range, you can select the Specify range of displayed pixel values check box and enter the range for your data. The dialog box automatically displays the range based on the data type of the pixel values.
To view basic information about the image data, click the Video
Information button
in the Movie Player toolbar or select Video
Information from the Tools menu. The Movie Player displays
a dialog box containing basic information about the image sequence,
such as the size of each frame, the frame rate, and the total number
of frames.

To view multiple frames in a multiframe array at one time, use the montage function. montage displays all the image frames, arranging them into a rectangular grid. The montage of images is a single image object. The image frames can be grayscale, indexed, or truecolor images. If you specify indexed images, they all must use the same colormap.
This example creates an array of truecolor images and uses montage to display them all at once. Note how montage displays the images in a 2-by-2 grid. The first image frame is displayed in the first position of the first row, the next frame in the second position of the first row, and so on.
onion = imread('onion.png');
onionArray = repmat(onion, [ 1 1 1 4 ]);
montage(onionArray);

montage supports several optional parameters that you can use to customize the display. For example, using the 'size' parameter, you can specify the number of rows and columns montage uses to display the images. To display the onion images in one horizontal row, specify the 'size' parameter with the value [1 NaN]. When you specify NaN for a dimension, montage calculates the number of images to display along that dimension. Using montage parameters you can also specify which images in the image array you want to display, and adjust the contrast of the images displayed. See montage for more information.
To create a MATLAB movie from a multiframe image array, use the immovie function. This example creates a movie from a multiframe indexed image.
mov = immovie(X,map);
In the example, X is a four-dimensional array of images that you want to use for the movie.
To play the movie, use the implay function.
implay(mov);
This example loads the multiframe image mri.tif and makes a movie out of it. It won't do any good to show the results here, so try it out; it's fun to watch.
mri = uint8(zeros(128,128,1,27));
for frame=1:27
[mri(:,:,:,frame),map] = imread('mri.tif',frame);
end
mov = immovie(mri,map);
implay(mov);Note To view a MATLAB movie, you must have MATLAB software installed. To make a movie that can be run outside the MATLAB environment, use the avifile and addframe functions to create an AVI file, or use movie2avi. AVI files can be created using indexed and RGB images of classes uint8 and double, and don't require a multiframe image. |
![]() | Cropping an Image Using the Crop Image Tool | Displaying Different Image Types | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |