|On this page…|
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. The Image Viewer 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 Video Viewer app (implay). The Video Viewer app 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 Video Viewer app to view image sequences and provides information about configuring the Video Viewer app.
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.
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
Click the Video Viewer app in the apps gallery and select the Import from workspace option on the File menu. You can also call implay, specifying the name of the image sequence variable as an argument.
The Video Viewer opens, displaying the first frame of the image sequence. Note how the Video Viewer 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 Video Viewer 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 Video Viewer 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 Video Viewer 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 in the Playback toolbar or select Playback Modes from the Playback menu. You can select forward, backward, or autoreverse. As you click the playback mode button, it cycles through these options and the appearance changes to indicate the current selection.||A|
|View the sequence repeatedly.||Click the Repeat button in the Playback toolbar or select Playback Modes > Repeat from the Playback menu. You toggle this option on or off.||R|
|Jump to a specific frame in the sequence.||Click the Jump to button in the Playback toolbar or select Jump to from the Playback menu. This option opens a dialog box in which you can specify the number of the frame.||J|
|Stop the sequence.||Click the Stop button in the Playback toolbar or select Stop from the Playback menu. This button is only enabled when an image sequence is playing.||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 in the Playback toolbar, in the desired direction, or select an option, such as Fast Forward or Rewind from the Playback menu.|
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 Video Viewer 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 in the toolbar or select Zoom In or Zoom Out from the Tools menu. Click the Pan button in the toolbar or select Pan from the Tools menu. If you click Maintain fit to window button in the toolbar or select Maintain fit to window or from the Tools menu, the zoom and pan buttons are disabled.|
|Examine an area of the current frame in detail.||Click the Pixel region button in the Playback toolbar or select Pixel Region from the Tools menu.|
|Export frame to Image Viewer||Click the Export to Image Tool button in the Playback toolbar or select Export to Image Tool from the File menu. The Video Viewer app opens an Image Viewer containing the current frame.|
The Video Viewer app Configuration dialog box enables you to change the appearance and behavior of the player. To open the Configuration dialog box, select File > Configuration > Edit. (To load a preexisting configuration set, select File > Configuration > Load.)
The Configuration dialog box contains four tabs: Core, Sources, Visuals, and Tools. On each tab, select a category and then click Properties to view configuration settings.
The following table lists the options that are available for each category on every pane.
|Pane||Option Category||Option Descriptions|
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.
Open message log 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.
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.
Select the Enabled check box to enable connections to Simulink models. You must have Simulink installed.
Select the Enabled check box to enable connections to files (the default).
Default open file path parameter — Specify the directory that is displayed in the Connect to File dialog box when you click File > Open.
Select the Enabled check box to enable connections to variables in the workspace (the default). There are no options associated with this selection.
|Visuals||Video||Select the Enabled check box to use video visualization.|
|Tools||Image Tool||Select the Enabled check box to include
the Image Viewer. |
Open new Image Tool window for each export check box — Opens a new Image Viewer for each exported frame.
|Tools||Pixel Region||Select the Enabled check box to include the Pixel Region tool in the Video Viewer app (the default).|
|Tools||Image Navigation Tools||Select the Enabled check box to include the zoom and pan tools in the Video Viewer app (the default).|
|Tools||Instrumentation Sets||Select the Enabled check box to include instrumentation sets in the Video Viewer app. Provides a way to save your current configuration.|
Note: By default, the Video Viewer 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 Video Viewer app plays the image sequence or video, and displays the actual playback rate. The playback rate is the number of frames the Video Viewer 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 Video Viewer app to achieve the playback rate by dropping frames. 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. If your hardware allows it, increase the refresh rate to achieve a smoother playback. However, if you specify a small range for the refresh rate, the computed frame replay schedule may lead to a choppy replay, and a warning will appear.
To specify the colormap to apply to the intensity values, select Colormap from the Tools menu, or use the keyboard shortcut C. The Video Viewer 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 Video Viewer toolbar or select Video Information from the Tools menu. The Video Viewer 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.
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 VideoWriter class to create a movie in a standard video format, such as, AVI.