| Image Processing Toolbox | ![]() |
Viewing Multiple Images
If you specify a file that contains multiple images, imshow only displays the first image in the file. To view all the images in the file, import the images into the MATLAB workspace by calling imread. See Reading Multiple Images from a Graphics File for more information.
Some applications create collections of images related by time or view, such as magnetic resonance imaging (MRI) slices or frames of data acquired from a video stream. The Image Processing Toolbox supports these collections of images as four-dimensional arrays, where each separate image is called a frame and the frames are concatenated along the fourth dimension. All the frames in a multiframe image must be the same size.
Once the images are in the MATLAB workspace, there are two ways to display them using imshow:
To view all the frames in a multiframe image at once, you can also use the montage function. See Displaying All Frames of a Multiframe Image at Once for more information.
Displaying Each Image in a Separate Figure
The simplest way to display multiple images is to display them in separate figure windows. MATLAB does not place any restrictions on the number of images you can display simultaneously. However, there are usually system limitations that are dependent on the computer hardware you are using.
imshow always displays an image in the current figure, so if you display two images in succession, the second image replaces the first image. To avoid replacing the image in the current figure, use the figure command to explicitly create a new empty figure before calling imshow for the next image. For example, to view the first three frames in an array of intensity images I,
When you use this approach, the figures you create are empty initially.
Displaying Multiple Images in the Same Figure
You can use the imshow function with the MATLAB subplot function or the MATLAB subimage function to display multiple images in a single figure window.
Dividing a Figure Window into Multiple Display Regions. subplot divides a figure into multiple display regions. The syntax of subplot is
This syntax divides the figure into an m-by-n matrix of display regions and makes the pth display region active.
For example, if you want to display two images side by side, use
[X1,map1]=imread('forest.tif'); [X2,map2]=imread('trees.tif'); subplot(1,2,1), imshow(X1,map2) subplot(1,2,2), imshow(X2,map2)
Two Images in Same Figure Using the Same Colormap
If sharing a colormap (using the subplot function) produces unacceptable display results, use the subimage function, described below. Or, as another alternative, you can map all images to the same colormap as you load them.
Using the subimage Function to Display Multiple Images. subimage converts images to RGB before displaying and therefore circumvents the colormap sharing problem. This example displays the same two images shown with better results.
[X1,map1]=imread('forest.tif'); [X2,map2]=imread('trees.tif'); subplot(1,2,1), subimage(X1,map1) subplot(1,2,2), subimage(X2,map2)
Two Images in Same Figure Using Separate Colormaps
| Specifying the Initial Image Size | Understanding Handle Graphics Object Property Settings | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |