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 2-D grayscale, binary, or indexed images, then concatenate the images in the third dimension to create a 3-D array of size m-by-n-by-p. Each of the p images has size m-by-n.
If you have a sequence of 2-D RGB images, then concatenate the images along the fourth dimension to create a 4-D array of size m-by-n-by-3-by-p. Each of the p images has size m-by-n-by-3.
The figure depicts 2-D images concatenated as planes of a 3-D 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
m-by-n-by-1-by-p.
If you need to convert a multiframe array of grayscale images to a 3-D 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 2-D transformation to all 2-D planes along the higher dimension.
Some toolbox functions that accept multidimensional 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 table lists common toolbox functions that support image sequences.
Function | Image Sequence Dimensions | Guideline When Used with an Image Sequence |
---|---|---|
m-by-n-by-p only | Must use the | |
m-by-n-by-p
or
|
| |
m-by-n-by-p
or
|
| |
m-by-n-by-p
or
|
| |
m-by-n-by-p only |
| |
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 |
| |
m-by-n-by-p only |
| |
m-by-n-by-p only |
| |
m-by-n-by-p
or
| Image sequences must be the same size. | |
m-by-n-by-p only |
| |
m-by-n-by-p only | Must use the | |
m-by-n-by-p only | Must use the | |
m-by-n-by-p
or
| With grayscale images, | |
m-by-n-by-p only | Must use the | |
m-by-n-by-p only | Must use the | |
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 |
| |
m-by-n-by-p only | Must use the | |
m-by-n-by-p only | Must use the | |
m-by-n-by-p
or
| Image sequences must be the same size. | |
m-by-n-by-p only |
| |
imwarp | m-by-n-by-p
or
|
|
m-by-n-by-p
or
|
| |
m-by-n-by-p only |
| |
m-by-n-by-p only |
| |
m-by-n-by-p only | Must use |