This section describes various ways you can view multiple images at the same time.
The simplest way to display multiple images at the same time is to display them in separate figure windows. MATLAB® does not place any restrictions on the number of images you can display simultaneously.
imshow always displays an image in the
current figure. If you display two images in succession, the second image replaces the first
image. To view multiple figures with
imshow, use the
figure command to explicitly create a new empty figure before calling
imshow for the next image. The following example views the first three
frames in an array of grayscale images
imshow(I(:,:,:,1)) figure, imshow(I(:,:,:,2)) figure, imshow(I(:,:,:,3))
You can view multiple images as a single image object in a figure window using the
montage function. By default,
montage scales the images, depending on the number of images and the
size of your screen, and arranges them to form a square.
preserves the aspect ratio of the original images. You can specify the size of the
thumbnails using the
The images in the montage can be of different types and sizes.
montage converts indexed images to RGB using the colormap present in
By default, the
montage function does not include any blank space
between the images in the montage. You can specify the amount of blank space between the
image using the
BorderSize parameter. You can also specify the color of
the space between images using the
The following example shows how to view a sequence of images as a montage.
This example shows how to view multiple frames in a multiframe array at one time, using the
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.
Create an array of truecolor images.
onion = imread('onion.png'); onionArray = repmat(onion, [ 1 1 1 4 ]);
Display all the images at once, in a montage. By default, the
montage function displays the images in a grid. The first image frame is in the first position of the first row, the next frame is in the second position of the first row, and so on.
To specify a different number of rows and columns, use the
'size' parameter. For example, to display the images in one horizontal row, specify the
'size' parameter with the value
[1 NaN]. Using other
montage parameters you can specify which images you want to display and adjust the contrast of the images displayed.
You can use the
imshow function with the MATLAB
subplot function to display multiple images in a single figure window.
For additional options, see Work with Image Sequences as Multidimensional Arrays.
The Image Viewer app (
imtool) does not support this
subplot divides a figure into multiple display regions. Using the
subplot(m,n,p), you define an
n matrix of display regions and specify which
p, is active.
For example, you can use this syntax to display two images side by side.
[X1,map1]=imread('forest.tif'); [X2,map2]=imread('trees.tif'); subplot(1,2,1), imshow(X1,map1) subplot(1,2,2), imshow(X2,map2)
imshowpair function displays a pair of images
in the same figure window. This display can be helpful when comparing images.
imshowpair supports many visualization methods, including:
falsecolor, in which the two images are overlaid in different color bands. Gray regions indicate where the images have the same intensity, and colored regions indicate where the image intensity values differ. RGB images are converted to grayscale before display in falsecolor.
alpha blending, in which the intensity of the display is the mean of the two input images. Alpha blending supports grayscale and truecolor images.
checkerboard, in which the output image consists of alternating rectangular regions from the two input images.
the difference of the two images. RGB images are converted to grayscale.
montage, in which the two images are displayed alongside each other. This
visualization mode is similar to the display using the
imshowpair uses optional spatial referencing information to display
the pair of images.