Viewing Image Sequences

Overview

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.

Viewing Image Sequences in the Movie Player

This section describes how to use the Movie Player to view image sequences and provides information about configuring the Movie Player.

Example: Viewing a Sequence of MRI Images

  1. 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
  2. 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.

  3. 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 OptionPlayback ControlKeyboard 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 options 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)

  4. 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 OptionPlayback 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. The Pixel Region tool closes if you play the image sequence.
    Export frame to Image ToolClick the Export to Image tool button in the Playback toolbar or select Export to Image Tool from the File menu. The Movie Player opens an Image Tool containing the current frame.

Configuring the Movie Player

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.

PaneOption CategoryOption Descriptions
CoreGeneral 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.

CoreSource 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.

SourceFile

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.

SourceWorkspace

Select the Enabled check box next to enable connections to variables in the workspace (the default). There are no options associated with this selection.

SourceSimulink

Select the Enabled check box next to enable connections to Simulink models. You must have Simulink installed.

ToolsImage 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.

ToolsPixel Region Select the Enabled check box to include the Pixel Region tool in the Movie Player (the default).
ToolsImage Navigation Tools Select the Enabled check box to include the zoom and pan tools in the Movie Player (the default).
ToolsInstrumentation 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.

Specifying the Frame Rate

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.

Specifying the Color Map

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.

Getting Information about the Image Frame

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.

Viewing Image Sequences as a Montage

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.

Converting a Multiframe Image to a Movie

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);

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS