| Image Processing Toolbox™ | ![]() |
| On this page… |
|---|
Overview of Toolbox Functions That Work with Image Sequences |
Some applications work with 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 or image stacks.
The ability to create N-dimensional arrays can provide a convenient way to store image sequences. For example, an m-by-n-by-p array can store an array of p two-dimensional images, such as grayscale or binary images, as shown in the following figure. An m-by-n-by-3-by-p array can store truecolor images where each image is made up of three planes.
Multidimensional Array Containing an Image Sequence

Many toolbox functions can operate on multi-dimensional arrays and, consequently, can operate on image sequences. For example, if you pass a multi-dimensional array to the imtransform function, it applies the same 2-D transformation to all 2-D planes along the higher dimension.
Some toolbox functions that accept multi-dimensional arrays, however, do not by default interpret an m-by-n-by-p or an m-by-n-by-3-by-p array as an image sequence. To use these functions with image sequences, you must use particular syntax and be aware of other limitations. The following table lists these toolbox functions and provides guidelines about how to use them to process image sequences. For information about displaying image sequences, see Viewing Image Sequences.
Function | Image Sequence Dimensions | Guideline When Used with an Image Sequence |
|---|---|---|
m-by-n-by-p only | Must use the bwlabeln(BW,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p or | PSF argument can be either 1-D or 2-D. | |
m-by-n-by-p or | PSF argument can be either 1-D or 2-D. | |
m-by-n-by-p or | PSF argument can be either 1-D or 2-D. | |
m-by-n-by-p only | nhood argument must be 2-D. | |
m-by-n-by-p or | Image sequences must be the same size. | |
m-by-n-by-p or | Image sequences must be the same size. Cannot add scalar to image sequence. | |
m-by-n-by-p only | SE argument must be 2-D. | |
m-by-n-by-p only | SE argument must be 2-D. | |
m-by-n-by-p only | SE argument must be 2-D. | |
m-by-n-by-p or | Image sequences must be the same size. | |
m-by-n-by-p only | SE argument must be 2-D. | |
m-by-n-by-p only | Must use the imextendedmax(I,h,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p only | Must use the imextendedmin(I,h,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p or | With grayscale images, h can be 2-D. With truecolor images (RGB), h can be 2-D or 3-D. | |
m-by-n-by-p only | Must use the imhmax(I,h,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p only | Must use the imhmin(I,h,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p or | Image sequences must be the same size. | |
m-by-n-by-p or | Image sequences must be the same size. | |
m-by-n-by-p only | SE argument must be 2-D. | |
m-by-n-by-p only | Must use the imextendedmax(I,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p only | Must use the imextendedmin(I,conn) syntax with a 2-D connectivity. | |
m-by-n-by-p or | TFORM argument must be 2-D. | |
m-by-n-by-p or | Image sequences must be the same size. | |
m-by-n-by-p only | SE argument must be 2-D. | |
m-by-n-by-p or | PADSIZE argument must be a two-element vector. | |
m-by-n-by-p only | NHOOD argument must be 2-D. | |
m-by-n-by-p only | NHOOD argument must be 2-D. | |
m-by-n-by-p or | T must be 2-D to 2-D (compatible with imtransform). | |
m-by-n-by-p only | Must use watershed(I,conn) syntax with a 2-D connectivity. |
This example starts by reading a series of images from a directory into the MATLAB workspace, storing the images in an m-by-n-by-p array. The example then passes the entire array to the stdfilt function and performs standard deviation filtering on each image in the sequence. Note that, to use stdfilt with an image sequence, you must use the nhood argument, specifying a 2-D neighborhood.
% Create an array of filenames that make up the image sequence
fileFolder = fullfile(matlabroot,'toolbox','images','imdemos');
dirOutput = dir(fullfile(fileFolder,'AT3_1m4_*.tif'));
fileNames = {dirOutput.name}';
numFrames = numel(fileNames);
I = imread(fileNames{1});
% Preallocate the array
sequence = zeros([size(I) numFrames],class(I));
sequence(:,:,1) = I;
% Create image sequence array
for p = 2:numFrames
sequence(:,:,p) = imread(fileNames{p});
end
% Process sequence
sequenceNew = stdfilt(sequence,ones(3));
% View results
figure;
for k = 1:numFrames
imshow(sequence(:,:,k));
title(sprintf('Original Image # %d',k));
pause(1);
imshow(sequenceNew(:,:,k),[]);
title(sprintf('Processed Image # %d',k));
pause(1);
endThe toolbox includes two functions, immovie and montage, that work with a specific type of multi-dimensional array called a multi-frame array. In this array, images, called frames in this context, are concatenated along the fourth dimension. Multi-frame arrays are either m-by-n-by-1-by-p, for grayscale, binary, or indexed images, or m-by-n-by-3-by-p, for truecolor images, where p is the number of frames.
For example, a multi-frame array containing five, 480-by-640 grayscale or indexed images would be 480-by-640-by-1-by-5. An array with five 480-by-640 truecolor images would be 480-by-640-by-3-by-5.
Note To process a multi-frame array of grayscale images as an image sequence, as described in Working with Image Sequences, you can use the squeeze function to remove the singleton dimension. |
You can use the cat command to create a multi-frame array. For example, the following stores a group of images (A1, A2, A3, A4, and A5) in a single array.
A = cat(4,A1,A2,A3,A4,A5)
You can also extract frames from a multiframe image. For example, if you have a multiframe image MULTI, this command extracts the third frame.
FRM3 = MULTI(:,:,:,3)
Note that, in a multiframe image array, each image must be the same size and have the same number of planes. In a multiframe indexed image, each image must also use the same colormap.
![]() | Converting Between Image Classes | Image Arithmetic | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |