This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Display Multiple Images

This section describes various ways you can view multiple images at the same time.

Display Multiple Images in Separate Figure Windows

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 I.

imshow(I(:,:,:,1))
figure, imshow(I(:,:,:,2))
figure, imshow(I(:,:,:,3))

Display Multiple Images in a Montage

You can view multiple images as a single image object in a figure window using the function. By default, the montage function scales the images, depending on the number of images and the size of your screen, and arranges them to form a square, preserving the aspect ratio of the original images. You can specify the size of the thumbnails using the parameter.

The images in the montage can be of different types and sizes. montage converts indexed images to RGB using the colormap present in the file.

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 BackgroundColor parameter.

The following example shows how to view a sequence of images as a montage.

View Image Sequence as Montage

This example shows how to view multiple frames in a multiframe array at one time, using the montage function. 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.

montage(onionArray);

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.

montage(onionArray,'size',[1 NaN]);

Display Images Individually in the Same Figure

You can use the imshow function with the MATLAB subplot function to display multiple images in a single figure window. For additional options, see What Is an Image Sequence?.

Note

The Image Viewer app (imtool) does not support this capability.

Divide a Figure Window into Multiple Display Regions

subplot divides a figure into multiple display regions. Using the syntax subplot(m,n,p), you define an m-by-n matrix of display regions and specify which region, 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)

Compare a Pair of Images

The imshowpair function combines a pair of images in the same figure window to assist in the comparison of the 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 montage function.

imshowpair uses optional spatial referencing information to display the pair of images.

See Also

Related Topics