Main Content

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.


Display Multiple Images in a Montage

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. montage preserves the aspect ratio of the original images. You can specify the size of the thumbnails using the ThumbnailSize name-value argument.

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.


Figure contains an axes object. The axes object contains an object of type image.

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]);

Figure contains an axes object. The axes object contains an object of type image.

Display Images Individually in the Same Figure

You can use the imshow function with the subplot function to display multiple images in a single figure window. For additional options, see Work with Image Sequences as Multidimensional Arrays.

You can display multiple images with different colormaps in the same figure using imshow with the tiledlayout and nexttile functions.


The Image Viewer app 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.

subplot(1,2,1), imshow(X1,map1)
subplot(1,2,2), imshow(X2,map2)

Two images displayed in the same figure window.

Compare a Pair of Images

The 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 montage function.

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

See Also

| |

Related Topics