Image Processing Toolbox User's Guide Previous page   Next Page

Reading a Graphics Image

The imread function reads an image from any supported graphics image file format, in any of the supported bit depths. Most image file formats use 8 bits to store pixel values. When these are read into memory, MATLAB stores them as class uint8. For file formats that support 16-bit data, PNG and TIFF, MATLAB stores the images as class uint16.

For example, this code reads a truecolor image into the MATLAB workspace as the variable RGB.

This code reads an indexed image with its associated colormap into the MATLAB workspace in two separate variables.

In these examples, imread infers the file format to use from the contents of the file. You can also specify the file format as an argument to imread. MATLAB supports many common graphics file formats, such as Microsoft Windows Bitmap (BMP), Graphics Interchange Format (GIF), Joint Photographic Experts Group (JPEG), Portable Network Graphics (PNG), and Tagged Image File Format (TIFF) formats. For the latest information concerning the bit depths and/or image formats supported, see the reference page for the imread and imformats functions.

Reading Multiple Images from a Graphics File

MATLAB supports several graphics file formats, such as HDF and TIFF, that can contain multiple images. By default, imread imports only the first image from a file. To import additional images from the file, use the syntax supported by the file format.

For example, when used with TIFF files, you can use an index value with imread that identifies the image in the file you want to import. This example reads a series of 27 images from a TIFF file and stores the images in a four-dimensional array. You can use imfinfo to determine how many images are stored in the file.

When a file contains multiple images that are related in some way, such as a time sequence, you can store the images in MATLAB as a 4-D array. All the images must be the same size. For more information, see Multiframe Image Arrays.

Previous page  Reading and Writing Image Data Writing a Graphics Image Next page

© 1994-2005 The MathWorks, Inc.