Image Processing Toolbox | ![]() ![]() |
Displaying Multiframe Images
A multiframe image is an image file that contains more than one image. The MATLAB-supported formats that enable the reading and writing of multiframe images are HDF and TIFF. See Multiframe Image Arrays for more information about reading and writing multiframe images.
Once read into MATLAB, the image frames of a multiframe image are always handled in the fourth dimension. Multiframe images can be loaded from disk using a special syntax of imread
, or created using MATLAB. Multiframe images can be displayed in several different ways; to display a multiframe image, you can
imshow
function. See Displaying the Frames of a Multiframe Image Individually below.
montage
function. See Displaying All Frames of a Multiframe Image at Once.
immovie
function. See Converting a Multiframe Image to a Movie.
Displaying the Frames of a Multiframe Image Individually
In MATLAB, the frames of a multiframe image are handled in the fourth dimension. To view an individual frame, call imshow
and specify the frame using standard MATLAB indexing notation. For example, to view the seventh frame in the intensity array I
,
The following example loads mri.tif
and displays the third frame.
% Initialize an array to hold the 27 frames of mri.tif mri = uint8(zeros(128,128,1,27)); for frame=1:27 % Read each frame into the appropriate frame in memory [mri(:,:,:,frame),map] = imread('mri.tif',frame); end imshow(mri(:,:,:,3),map);
Intensity, indexed, and binary multiframe images have a dimension of m-by-n-by-1-by-k, where k represents the total number of frames, and 1 signifies that the image data has just one color plane. Therefore, the following call,
RGB multiframe images have a dimension of m-by-n-by-3-by-k, where k represents the total number of frames, and 3 signifies the existence of the three color planes used in RGB images. This example,
shows all three color planes of the seventh frame, and is not equivalent to
which shows only the third color plane (blue) of the seventh frame. These two calls will only yield the same results if the image is RGB grayscale (R=G=B).
Displaying All Frames of a Multiframe Image at Once
To view all of the frames in a multiframe array at one time, use the montage
function. montage divides a figure into multiple display regions and displays each image in a separate region.
The syntax for montage
is similar to the imshow
syntax. To display a multiframe intensity image, the syntax is
To display a multiframe indexed image, the syntax is
This example loads and displays all frames of a multiframe indexed image.
% Initialize an array to hold the 27 frames of mri.tif. mri = uint8(zeros(128,128,1,27)); for frame=1:27 % Read each frame into the appropriate frame in memory. [mri(:,:,:,frame),map] = imread('mri.tif',frame); end montage(mri,map);
Figure 3-1: All Frames of Multiframe Image Displayed in One Figure
Notice that montage displays images in a row-wise manner. The first frame appears in the first position of the first row, the next frame in the second position of the first row, and so on. montage
arranges the frames so that they roughly form a square.
Converting a Multiframe Image to a Movie
To create a MATLAB movie from a multiframe image array, use the immovie
function.
This call creates a movie from a multiframe indexed image X
where X
is a four-dimensional array of images that you want to use for the movie.
You can play the movie in MATLAB using the movie
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.
% Initialize and array to hold the 27 frames of mri.tif. mri = uint8(zeros(128,128,1,27)); for frame=1:27 % Read each frame into the appropriate frame in memory. [mri(:,:,:,frame),map] = imread('mri.tif',frame); end mov = immovie(mri,map); movie(mov);
Note that immovie
displays the movie as it is being created, so you will actually see the movie twice. The movie runs much faster the second time (using movie
).
Note
MATLAB movies require MATLAB in order to be run. To make a movie that can be run outside of MATLAB, you can use the MATLAB avifile and addframe functions to create an AVI file. AVI files can be created using indexed and RGB images of classes uint8 and double , and don't require a multiframe image. For instructions on creating an AVI file, see the Development Environment section in the MATLAB documentation.
|
![]() | Adding a Colorbar | Displaying Multiple Images | ![]() |