Work with Image Sequences as Multidimensional Arrays
Create Multidimensional Array Representing Image Sequence
Multidimensional arrays are a convenient way to display and process image sequences. Create a multidimensional array by concatenating the individual images of an image sequences. Each image must be the same size and have the same number of color channels. If you are storing a sequence of indexed images, each image must use the same colormap.
If you have a sequence of 2D grayscale, binary, or indexed images, then concatenate the images in the third dimension to create a 3D array of size mbynbyp. Each of the p images has size mbyn.
If you have a sequence of 2D RGB images, then concatenate the images along the fourth dimension to create a 4D array of size mbynby3byp. Each of the p images has size mbynby3.
The figure depicts 2D images concatenated as planes of a 3D array.
Use the cat
function to
concatenate individual images. For example, this code concatenates a group of RGB
images along the fourth dimension.
A = cat(4,A1,A2,A3,A4,A5)
Note
Some functions work with a particular type of multidimensional array, call a
multiframe array. In a multiframe array, images are
concatenated along the fourth dimension regardless of the number of color
channels that the images have. A multiframe array of grayscale, binary, or
indexed images has size
mbynby1byp.
If you need to convert a multiframe array of grayscale images to a 3D array for
use with other toolbox functions, then you can use the squeeze
function
to remove the singleton dimension.
Display Image Sequences
There are several ways to display image sequences. To display one frame at a time,
use the Image Viewer app or the imshow
function. To display all the
frames in an image sequence simultaneously, use the montage
function.
To animate an image sequence or provide navigation within the sequence, use the Video Viewer app. The Video Viewer app provides playback controls that you can use to navigate among the frames in the sequence.
Process Image Sequences
Many toolbox functions can operate on multidimensional arrays and, consequently,
can operate on image sequences. For example, if you pass a multidimensional array to
the imwarp
function, it applies the
same 2D transformation to all 2D planes along the higher dimension.
Some toolbox functions that accept multidimensional arrays, however, do not by default interpret an mbynbyp or an mbynby3byp array as an image sequence. To use these functions with image sequences, you must use particular syntax and be aware of other limitations. The table lists common toolbox functions that support image sequences.
Function  Image Sequence Dimensions  Guideline When Used with an Image Sequence 

mbynbyp only  Must use the  
mbynbyp
or

 
mbynbyp
or

 
mbynbyp
or

 
mbynbyp only 
 
mbynbyp
or
 Image sequences must be the same size.  
mbynbyp
or
 Image sequences must be the same size. Cannot add scalar to image sequence.  
mbynbyp only 
 
mbynbyp only 
 
mbynbyp only 
 
mbynbyp
or
 Image sequences must be the same size.  
mbynbyp only 
 
mbynbyp only  Must use the  
mbynbyp only  Must use the  
mbynbyp
or
 With grayscale images,  
mbynbyp only  Must use the  
mbynbyp only  Must use the  
mbynbyp
or
 Image sequences must be the same size.  
mbynbyp
or
 Image sequences must be the same size.  
mbynbyp only 
 
mbynbyp only  Must use the  
mbynbyp only  Must use the  
mbynbyp
or
 Image sequences must be the same size.  
mbynbyp only 
 
imwarp  mbynbyp
or


mbynbyp
or

 
mbynbyp only 
 
mbynbyp only 
 
mbynbyp only  Must use 