MATLAB Function Reference
  Go to function:
    Search    Help Desk 
imread    Examples   See Also

Read image from graphics file

Synopsis

Description

A = imread(filename,fmt) reads the image in filename into A, whose class is uint8. If the file contains a grayscale intensity image, A is a two-dimensional array. If the file contains a truecolor (RGB) image, A is a three-dimensional (m-by-n-by-3) array. filename is a string that specifies the name of the graphics file, and fmt is a string that specifies the format of the file. The file must be in the current directory or in a directory in the MATLAB path. If imread cannot find a file named filename, it looks for a file named filename.fmt.

This table lists the possible values for fmt:

Format
File type
'bmp'
Windows Bitmap (BMP)
'hdf'
Hierarchical Data Format (HDF)
'jpg' or 'jpeg'
Joint Photographic Experts Group (JPEG)
'pcx'
Windows Paintbrush (PCX)
'tif' or 'tiff'
Tagged Image File Format (TIFF)
'xwd'
X Windows Dump (XWD)

[X,map] = imread(filename,fmt) reads the indexed image in filename into X and its associated colormap into map. X is of class uint8, and map is of class double. The colormap values are rescaled to the range [0, 1].

[...] = imread(filename) attempts to infer the format of the file from its content.

[...] = imread(...,idx) reads in one image from a multi-image TIFF file. idx is an integer value that specifies the order in which the image appears in the file. For example, if idx is 3, imread reads the third image in the file. If you omit this argument, imread reads the first image in the file.

[...] = imread(...,ref) reads in one image from a multi-image HDF file. ref is an integer value that specifies the reference number used to identify the image. For example, if ref is 12, imread reads the image whose reference number is 12. (Note that in an HDF file the reference numbers do not necessarily correspond to the order of the images in the file.) If you omit this argument, imread reads the first image in the file.

This table summarizes the types of images that imread can read:

Format
Variants
BMP
1-bit, 4-bit, 8-bit, and 24-bit uncompressed images; 4-bit and 8-bit run-length encoded (RLE) images
HDF
8-bit raster image datasets, with or without associated colormap; 24-bit raster image datasets
JPEG
Any baseline JPEG image; JPEG images with some commonly used extensions
PCX
1-bit, 8-bit, and 24-bit images
TIFF
Any baseline TIFF image, including 1-bit, 8-bit, and 24-bit uncompressed images; 1-bit, 8-bit, and 24-bit images with packbit compression; 1-bit images with CCITT compression
XWD
1-bit and 8-bit ZPixmaps; XYBitmaps; 1-bit XYPixmaps

Examples

This example reads the sixth image in a TIFF file:

This example reads the fourth image in an HDF file:

See Also

imfinfo     Return information about a graphics file

imwrite     Write an image to a graphics file



[ Previous | Help Desk | Next ]